I'm trying to create an extremely simple, basic riddle program where Python asks you if you are ready for the riddle, tells you the riddle, checks your answer and repeats.
My problem is I want to create "multiple" answers for the riddle, so it's less case sensitive. Here's my code:
r1Answer = input('')
if r1Answer == 'Silence' # This is where I tried to put my "and" function r1Answer == 'silence' :
print('Correct!')
else:
print('Not quite.')
In Line 2, I've already tried to put an and
function in between the two correct answers in my code.
CodePudding user response:
If you want to account for upper or lower you could do the follow:
r1Answer = input('')
if r1Answer.lower() == 'silence': # This is where I tried to put my "and" function r1Answer == 'silence' :
print('Correct!')
else:
print('Not quite.')
the .lower() function will make the string all lower case to keep everything organized...additionally you were missing a : at the end of your if part of your if/else statement, I want ahead and added it.
CodePudding user response:
You can just use a list with all correct answers -
correct_answers = ['ans1', 'ans2']
if answer in correct_answers:
print('Correct')