0
Python challenge question("male" or "female")
Sex = "F" if (Sex == "M" or "m"): Print("male") else: Print("female") #CAN SOMEBODY EXPLAIN WHY THE ANSWER IS MALE INSTEAD OF FEMALE? #i didn't create this question btwđI got this question and I got wrong in the challenge
5 Answers
0
that happend through the incorrect use of binary operators.
if Sex == 'M' or Sex == 'm'
+ 5
Good question and for the explanation of such kind of answer refer this...
https://stackoverflow.com/questions/20002503/why-does-a-b-or-c-or-d-always-evaluate-to-true
+ 1
Python evaluates any non-empty string, list, tuple, dict as True, also any non-zero number is evaluated as True when used with IF or a logical operator (OR,AND,NOT)
This is why "m" is evaluated as True, and you have to do the == comparison
0
#Python challenge question("male" or "female")
Sex = "F"
if (Sex == "M" or Sex == "m"):
print("male")
else:
print("female")
# use print in lowercase,
# condition must be written properly!
0
Kiran Deep Naidu Emanuel Maliaño Manish thanks everyone....I got this question in a challenge and got wrong so now I know and the Print is because it just auto corrects me when I write here and I didn't realize and I didn't downvote u guys btw đ