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?

27th Feb 2017, 7:14 AM
XENONIUM
XENONIUM - avatar
3 Respostas
+ 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
27th Feb 2017, 7:43 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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.
27th Feb 2017, 7:27 AM
Tony Loa
Tony  Loa - avatar
0
Thank you so much!
27th Feb 2017, 8:32 AM
XENONIUM
XENONIUM - avatar