0

Plzz help why this code is not working propely, its printing only first statement?

alien = 'green' or 'yellow' or 'red' if alien == 'green': print('earned 5') if alien == 'yellow': print('earned 10') if alien == 'red': print('earned 15') output: earned 5

5th Mar 2019, 2:31 PM
Muhammad Ahad
Muhammad Ahad - avatar
3 odpowiedzi
+ 2
A variable (say, var) can’t be ‘x’ or ‘y’ or ‘z’ where it will return True if var is equal to one of ‘x’, ‘y’ or ‘z’. You can have var = (‘x’, ‘y’, ‘z’) and say if ‘x’ in var: print(...) if ‘y’ in var: print(...) if ‘z’ in var: print(...)
5th Mar 2019, 2:41 PM
Russ
Russ - avatar
+ 2
You have created this question twice. Would you mind deleting 1 https://www.sololearn.com/Discuss/1713249/?ref=app
5th Mar 2019, 2:50 PM
Seniru
Seniru - avatar
0
you are right thanks for helpling.. its working fine.. alien1 = 'green,yellow,red' if 'green' in alien1: print(earned 5) .... ...
5th Mar 2019, 3:40 PM
Muhammad Ahad
Muhammad Ahad - avatar