jeudi 11 juillet 2019

Differences between "if in" and "if or if in"; looking for explanation

I get different results if I write "if X or y in var" than if I write "if x in var or if y in var." Why is that? I cannot find any documentation on this anywhere.

If, using the following Python3 code, I enter "rrrr" I get "whoohoo" not "WTF." Only if I remove the code "elif "read" or "road" in choice: print("whoohoo")," do I get "WTF." Can anyone enlighten me on what I'm missing about the difference in the two? As I say, I've searched broadly on the net and can't find anything on this. I'm expecting them both to return the same thing but they do not.

var = "read", "road"
print(var)
print("what is your choice?")

choice = input("> ")

if "raed"  in choice or "raad" in choice:
    print('Not Good')

elif "read" or "road" in choice:
    print("whoohoo")

elif "read" in choice or "road" in choice:
    print("excellent")

else:
    print("WTF")

Aucun commentaire:

Enregistrer un commentaire