M = 'Male' and 'male'
That statement does not do what you think. The expression X and Y
is a logical expression and returns True
if X
and Y
are equal, False
otherwise. And since 'Male' and 'male' are not equal, M
has the value False
. So your program will never recognise a Male gender. The correct code is:
if gender == 'Male' or gender == 'male':
if gender.lower() == 'male':
[edit]
My mistake on the expression above. In reality it will set M to 'male' as described at
Built-in Types — Python 3.10.0 documentation[
^]. However, the code I suggested should still do what I said.