-1

i'm very new to programming so please excuse the silly question. How do I make this loop so that if the person inputs a random string (which isn't yes or no) it will return "Invalid response"?

name = input("What's your name? ")
understanding = input("{}, do you understand while loops in python\n(Yes or No)? ".format(name))


while understanding.lower() != 'yes':
    print("Ok, {}, while loops in Python repeat as long as a certain Boolean condition is met.".format(name))
    understanding = input("{}, now do you understand Python while loops?\n(Yes or No)? ".format(name))
print("Great news {}! It's good to hear that you understand these loops now! Let's move on!".format(name))
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
  • 1
    Does this answer your question? [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – AMC Jan 19 '20 at 01:46

1 Answers1

0

Perhaps like this

if understanding.lower() not in ('yes','no'):
    print('Invalid response')