def say_hi(name, age, gender):
gender = input("Are you Male(M) or Female(F)? “)
if (gender.upper == “MALE” or gender.upper == “M”):
title = “Mr”
elif (gender.upper == “FEMALE” or gender.upper == “F”):
title = “Ms”
else:
title = “Mr/Ms”
print(f"Hello {title} {name}! You are aged {age}”)
say_hi(“John”, “30”, “M”)
str.upper
is a method, and you’re not calling it (you call a function/method with parentheses, which are the function call operator). Instead, your code is referencing the method itself, which is never going to be equal to "MALE"
, "M"
, "FEMALE"
, or "F"
.
Because of this, your if
and elif
are always going to evaluate to False
.
>>> gender = "male"
>>> gender.upper
<built-in method upper of str object at 0x7f5df9014570>
>>> gender.upper == "MALE"
False
>>> gender.upper()
'MALE'
>>> gender.upper() == "MALE"
True