Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A person is eligible to be a US senator if they are at least 30 years old and ha

ID: 3937407 • 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 arc 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: (1) "Eligible for the Senate and the House, " (2) 'Eligible only for the House, " or (3) "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 = [65,35,35,28,24,45,18];
   residency = [25,8,5,8,5,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();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote