Reputation: 533
I've searched everywhere for an answer to my question, and I still can't figure it out! The answer is probably sooooo simple but I just can't get it, maybe because I'm just getting back into Python...
Anyway, I want to create a while-loop so that until the user enters 'y' or 'n' the question will keep being asked. This is what I have:
while True: # to loop the question
answer = input("Do you like burgers? ").lower()
if answer == "y" or "n":
break
I'm honestly so baffed, so I beg for someone's help :)
Upvotes: 3
Views: 101
Reputation: 12986
Your condition is wrong. Also if you are using Python 2.x you should use raw_input
(otherwise you would need to type "y"
instead of y
, for example):
while True: # to loop the question
answer = raw_input("Do you like burgers? ").lower()
if answer == "y" or answer == "n":
break
Upvotes: 3
Reputation: 2881
while True: # to loop the question
answer = input("Do you like burgers? ").lower()
if answer == "y" or answer == "n":
break
Upvotes: 5