0
Python's 'OR'. HELP
if x == '1' or '2': print('Success') else: print('Unfortune') _________ x = '1' > Success x = '2' > Unfortune ________ WHY? HOW TO MAKE IT RIGHT?
3 odpowiedzi
+ 11
What you did here is actually:
if x == ('1' or '2')
so Python first evaluates ('1' or '2') which is '1' and only then it compares x to it
The condition should go:
if x=='1' or x=='2':
blabla
+ 2
if x == '1' :
print('Success')
elif x == '2':
print('Unfortune')
You have two (or if you will have more) different conditions you must use "elif" keyword in "if-else" operator or keyword "else", if you don't need handle other possible conditions.
0
Thank you so much!