I am currently a student who is struggling. OK, so I have a code that checks if you’re eligible to run for the presidency in the US. The problem is that the one and only non-number if statement question won’t give me an output if it doesn’t pass through the if statement. All the others work fine if I don’t input the right numbers to make me eligible except that one question. Here’s the code:
enter code here
age = int(input("Enter age: "))
if age >= 35:
age1 = 1
else:
age1 = 0
us = input("Are you born in the US? (Y/N): ")
if us == "Y":
us1 = 1
elif us == "N":
us1 = 0
res = float(input("Years of residancy in the US: "))
if res >= 14:
res1 = 1
else:
res1 = 0
if age1 + res1 + us1 == 3:
print("You are eligible to run for president")
else:
print("You are not eligable to run for president.")
>Solution :
Python is a language in which indentation matters, the fact that you put the last if/else block inside the else of the last question makes so that it only executes when you input a residency < 14.
To solve this, put it outside such block, de-indenting all four rows.