[Python] How do I get my code to reject invalid input and repeat the prompt? [duplicate]

Discussão em 'Python' iniciado por Stack, Dezembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    I need this code to only accept "y" or "n" for the sYesOrNo input. If user enters invalid input, I need it to re-display the sYesOrNo input prompt.

    It repeats the loop if user enters "y" and breaks out of the loop if user enters "n" like it's supposed to.

    But it also breaks out of the loop with invalid input.

    I cannot use functions for this. It can only be a loop.

    sYesOrNo = "y"
    while sYesOrNo == "y" :
    fSalesPrice = getFloatInput("Enter property sales value: ")
    fProperty_Values.append (fSalesPrice)
    sYesOrNo = input("Enter another value Y or N: ").lower()
    if sYesOrNo == "n" :
    break

    Continue reading...

Compartilhe esta Página