Here is a Python program that checks if someone is eligible to run for president in the United States based on the criteria you've provided:
# Function to check presidential eligibility
def check_presidential_eligibility():
# Ask for the user's age
age = int(input("Age: "))
# Ask if the user was born in the U.S.
born_in_us = input("Born in the U.S.? (Yes/No): ")
# Ask for the number of years they've been a resident
years_of_residency = int(input("Years of Residency: "))
# Determine eligibility
if age >= 35 and born_in_us == "Yes" and years_of_residency >= 14:
print("You are eligible to run for president!")
else:
print("You are not eligible to run for president.")
# Call the function to execute the program
check_presidential_eligibility()
How the program works:
- It prompts the user for their age and converts it to an integer.
- It asks whether the user was born in the U.S. and stores the response as a string.
- It requests the number of years the user has been a resident in the U.S. and converts that to an integer.
- Using an if/else statement, it checks if the user meets the necessary criteria to run for president.
- It prints a message based on whether the user is eligible or not.
Important Notes:
- Ensure you run this code in an environment that supports Python input/output.
- The program checks for exact matches in capitalization, ensuring that only 'Yes' or 'No' are valid responses.