mardi 17 août 2021

Why is my Python 3 code always printing the first option in an if:else? [duplicate]

I just started teaching myself Python 3 with Automate the Boring Stuff. While screwing around I wrote this small piece of code:

#Sets up question and assigns variable
print ('What is your favorite game?')
favoriteGame = input()

#Checks if favoriteGame is Runescape 3
if favoriteGame == 'RuneScape' or 'RS3' or 'RuneScape 3':
    print ('Nice, a fellow RS3 player!')

#Checks if favoriteGame is Old School RuneScape
elif favoriteGame == 'Old School RuneScape' or 'OSRS':
    print ('Aw, an OSRS player? Go to hell!')

#Insults non-RuneScape players
else:
    print ('Man, you don\'t even play RuneScape. Get outta here.')

when running this code it always prints "Nice, a fellow RS3 player!" No matter what the answer is. I have a similar issue with this other bit of code:

# Write your code here :-)
name = ""
while name != 'your name':
    print ('Please type your name.')
    name = input()
print = ('Thank you!')

it never prints "Thank you!". Even after typing "your name". I don't think this is a glitch because I also tried running the code in a in-browser version of Python. I just wrote it wrong, but I cannot figure out where after comparing to the examples.

Aucun commentaire:

Enregistrer un commentaire