I'm quite a newbie to programming and python. Though, I have taken a few lessons at www.udacity.com and www.codecademy.com.
I have a problem with this nested if
/else
statement towards the bottom of the code block, the "nested" if
statement is running but the elif
statement after that is not running as it was supposed to when an Age
value of less than 18 is entered. I get no error messages when I run this in the Python IDLE which is v. 2.5.4 leading me to believe that there is a problem similar to that of white space where the if
statement does not expect an else
or elif
statement and thinks that the code ends with that nested if
statement.
The last output is the first of the two print statements in the nested if
/else
statement.
I have searched for answers to my problem but none of the sources I find give me the answer to this specific problem and I can't figure out what is wrong with the code. Perhaps, I'm just blind.
print("Welcome")
Name = raw_input("Enter your name ")
print("Hello, " + Name + ".")
Age = raw_input("Enter your age ")
Gender = raw_input("Gender? ")
if Gender == "M" or "Male" or "male" or "boy" or "Boy":
if Age >= 18:
print ("You are " + Name + ", a " + Age + " year old man.")
elif Age < 18:
print ("You are " + Name + ", a " + Age + " year old boy.")