+ 4

Why this code execute male.

sex=('f') if(sex=='M' or 'm'): print('male') else: print('female') output=male #but why can you explain me.

19th Mar 2018, 2:32 PM
Maninder $ingh
Maninder $ingh - avatar
2 Answers
+ 7
or 'm' is True, should be ... if(sex =='M' or sex=='m'): ...
19th Mar 2018, 2:53 PM
Louis
Louis - avatar
+ 1
print (sex=='M') print ((sex=='M') or 'm') try to print like above and if atatment will exscute for any value other than zero. below code also prints male. if('m'): print('male') else: print('female')
17th May 2018, 4:39 PM
$Ā¢šŽā‚¹š”­!šØš“
$Ā¢šŽā‚¹š”­!šØš“ - avatar