+ 1

Help me , why this code is not working properly? 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:36 PM
Muhammad Ahad
Muhammad Ahad - avatar
3 ответов
+ 5
Muhammad Ahad nope only green is stored in alien.
5th Mar 2019, 2:59 PM
Seniru
Seniru - avatar
+ 4
When using or with strings the first option will be returned as the value. So the alien will have the value as green and therefore it will print 'earned 5'
5th Mar 2019, 2:48 PM
Seniru
Seniru - avatar
0
okay.. what about other statments? that are also true..
5th Mar 2019, 2:53 PM
Muhammad Ahad
Muhammad Ahad - avatar