dimanche 13 novembre 2016

how to use or in a if statement in Python?

I'm trying to check if "answer" is either y, yes, j or ja in Python.

answer = input("Change parameters? (y/yes/j/ja)"):

if (answer == 'y') or (answer == "yes") or (answer == "j") or (answer == "ja"):
    #code

If I execute the code, it throws this error if I type in eg. ja

Traceback (most recent call last):
  File "stream.py", line 41, in <module>
    answer = input("Parameter anpassen? (y/yes/j/ja)")
  File "<string>", line 1, in <module>
NameError: name 'ja' is not defined

How can I solve this error or is there a way to do this more compact, especially to shorten the if statement?

Aucun commentaire:

Enregistrer un commentaire