-4

I need help if someone types a wrong input it should return the question again in python3.

I tried to return the variable.

def main():
    this = input ('Is this your ..? (Yes/No)')
    if this != 'Yes' and this != 'No':
        print ('please provide a valid answer')

I want to ask the question again and again until the answer will be Yes or No.

Davidoff7776
  • 23
  • 1
  • 7

1 Answers1

0

incorporate some while loop:

I'd also keep in mind that in this case, it is case sensitive. So if someone answers 'yes' or 'YES' instead of 'Yes', it'll keep asking

def main():
    this = input ('Is this your ..? (Yes/No)')
    while this != 'Yes' and this != 'No':
        print ('please provide a valid answer')
        this = input ('Is this your ..? (Yes/No)')
chitown88
  • 27,527
  • 4
  • 30
  • 59
  • Sorry, but this is not the entire function that I posted and if I loop the function, other inputs will appear. – Davidoff7776 Jan 26 '19 at 10:31
  • this is the entire function you posted, and it answers your direct question of "to ask the question again and again until the answer will be Yes or No". If there's more to this, then you need to include that in your original question. – chitown88 Jan 26 '19 at 10:36
  • 1
    @chitown88, Do `while` looping inside function, so OP can have other inputs before or after the loop still inside function. – Austin Jan 26 '19 at 10:39
  • @Austin, good call – chitown88 Jan 26 '19 at 10:40