dimanche 28 juin 2015

multiple acceptable answers for an if statement on python 3 [duplicate]

This question already has an answer here:

run_program = (1)

while run_program==1:

 ###bulk of program goes here
user_answer = input('Do you have another item you would like to check')#request the answer of whether a user wishes to re run program

    if user_answer == 'yes' :#currently only working with the typed word yes 
        run_program = (1)# when statement is correct  run program continues to = 1 so the program continues to run

else:
        run_program =(2) # run program no longer =1 so program ends

How do I make the if statement recognise multiple answers as acceptable?

So yes is as acceptable as y or yeah or any other user input I list. I assumed it would be something like if user_answer == ['yes','yeah','y']: but it does not seem to work.

Aucun commentaire:

Enregistrer un commentaire