So I am pretty new to python but am having some trouble creating a basic Yes or No input. I want to be able to do something if the user says yes, do something else if the user says no, and repeat the question if the user inputs something that isn’t yes or no. Here is my code :
def yes_or_no():
YesNo = input("Yes or No?")
YesNo = YesNo.lower()
if(YesNo == "yes"):
return 1
elif(YesNo == "no"):
return 0
else:
return yes_or_no()
yes_or_no()
if(yes_or_no() == 1):
print("You said yeah!")
elif(yes_or_no() == 0):
print("You said nah!")
In theory this should work but I keep getting a glitch. Whenever I enter yes or no the first time, it always repeats the question. It works fine the second time. Please let me know what I am doing wrong. Thanks!