Sure! Below is a Python program that implements the requirements you described for determining presidential eligibility based on the user's age, citizenship, and residency.
# Ask the user for their age and store it in a variable
age = int(input("Age: "))
# Ask the user if they were born in the U.S.
born_in_us = input("Born in the U.S.? (Yes/No): ")
# Ask the user how long they’ve been a resident in the U.S.
years_of_residency = int(input("Years of Residency: "))
# Initialize eligibility status
eligible = True
eligibility_reasons = []
# Check age eligibility
if age < 35:
eligible = False
eligibility_reasons.append("You are too young. You must be at least 35 years old.")
# Check citizenship
if born_in_us != "Yes":
eligible = False
eligibility_reasons.append("You must be born in the U.S. to run for president.")
# Check residency duration
if years_of_residency < 14:
eligible = False
eligibility_reasons.append("You have not been a resident for long enough.")
# Final eligibility output
if eligible:
print("You are eligible to run for president!")
else:
print("You are not eligible to run for president.")
# Print the reasons for not being eligible
for reason in eligibility_reasons:
print(reason)
How It Works
- The program prompts the user for their age, whether they were born in the U.S., and how long they’ve been a resident in the U.S.
- It verifies the user's eligibility to run for president based on the provided conditions:
- At least 35 years old.
- Must have been born in the U.S.
- Must have been a resident for at least 14 years.
- If the user does not meet one or more of these conditions, the program collects reasons for ineligibility.
- Finally, it outputs whether the user is eligible or not and provides explanations for any conditions they did not meet.
Example Outputs:
- If the user enters age 19, born in the U.S. as "Yes", and years of residency as 19, the output will be:
You are not eligible to run for president.
You are too young. You must be at least 35 years old.
- If the user enters age 40, born in the U.S. as "No", and years of residency as 5, the output will be:
You are not eligible to run for president.
You must be born in the U.S. to run for president.
You have not been a resident for long enough.
Make sure to run this code in a Python environment to see how it works!