A person is eligible to be a US senator if they are at least 30 years old and ha
ID: 3937424 • Letter: A
Question
A person is eligible to be a US senator if they are at least 30 years old and have been a US citizen for at least 9 years. To be a US representative these numbers are 25 and 7, respectively Write a function, called congress(). that takes two formal parameters: a person's age (int) and years of citizenship (int) as input and returns their eligibility for the Senate and House. The return value of the function is one of the following three: "Eligible for the Senate and the House, " "Eligible only for the House, " or "Not eligible for Congress." The caller of the function congress() in the test() function then prints a message using the format shown in the next problem. You must use if-elif-else statements in your solution. Your congress() function must not print anything. Do not import external module in your solution Write a test function, called test(). to test the congress() function with the following actual parameters and write a message accordingly: Call test() in your program and show the result. Examples of the correct output format include: Age 45 with 17 years of citizenship: Eligible for the Senate and the House Age 18 with 18 years of citizenship: Not eligible for Congress.Explanation / Answer
def congress( person_age, years_of_citizenship ):
eligible_for_us_senator = False;
eligible_for_us_representative = False;
if( person_age >= 25 and years_of_citizenship >= 7):
eligible_for_us_representative = True;
if( person_age >= 30 and years_of_citizenship >= 9):
eligible_for_us_senator = True;
if( eligible_for_us_senator and eligible_for_us_representative ):
return "Eligible for the Senate and the House";
elif( eligible_for_us_representative ):
return "Eligible only for the House";
else:
#if not eligible_for_us_representative, then also not eligible_for_us_senator
return "Not eligible for Congress";
def test():
ages = [45,18];
residency = [17,18];
for i in range(len(ages)):
result = congress( ages[i], residency[i] );
print 'Age '+str(ages[i])+' with '+str(residency[i])+' years of citizenship: '+result;
test();
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.