A person is eligible to be a US senator if they are at least

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.

Solution

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();

 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 numb

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site