Who can be president?

The U.S. Constitution lists three qualifications for the presidency:

  • The person must be at least 35 years old.
  • The person must be a natural-born citizen1 of the United States.
  • The person must have been a resident in the United States for at least 14 years.

In Listing 1, the main function receives a person’s age, citizenship status, and years of residency as parameters. It calls check_eligibility and prints a message based on the Boolean value returned by that function.

Listing 1: The is_citizen parameter is True when the person was a U.S. citizen from birth and False otherwise.
def main(age: int, is_citizen: bool, years_resident: int) -> None:
    if check_eligibility(age, is_citizen, years_resident):
        print("You are eligible.")
    else:
        print("You are not eligible.")

In Listing 2, we have several implementations of check_eligibility. Each function should return True only when all three requirements are met and False otherwise.

Listing 2: Alternative implementations of check_eligibility for determining whether a person is eligible to become president (Question 1).
(a)
def check_eligibility(
    age: int,
    is_citizen: bool,
    years_resident: int,
) -> bool:
    if age >= 35 and years_resident >= 14:
        return is_citizen
    else:
        return False
(b)
def check_eligibility(
    age: int,
    is_citizen: bool,
    years_resident: int,
) -> bool:
    if age >= 35 or is_citizen or years_resident >= 14:
        return True
    else:
        return False
(c)
def check_eligibility(
    age: int,
    is_citizen: bool,
    years_resident: int,
) -> bool:
    if age < 35 or years_resident < 14:
        return False
    else:
        return True
(d)
def check_eligibility(
    age: int,
    is_citizen: bool,
    years_resident: int,
) -> bool:
    is_old_enough = age >= 35
    has_enough_residency = years_resident >= 14
    return is_old_enough and is_citizen and has_enough_residency

Which pair of implementations of check_eligibility correctly determines whether a person is eligible to become president based on their age, citizenship status, and years of residency?

Footnotes

  1. The citizenship requirement concerns when a person became a U.S. citizen. For example, Elon Musk, a South African-born entrepreneur, and Arnold Schwarzenegger, an Austrian-born actor and politician, are both naturalized citizens, so they are not eligible to become president.↩︎