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

Python: A person is eligible to be a US Senator who is at least 30 years old and

ID: 3849244 • Letter: P

Question

Python:

A person is eligible to be a US Senator who is at least 30 years old and has been a US citizen for at least 9 years. Write an initial version of a program congress.py to obtain age and length of citizenship from the user and print out if a person is eligible to be a Senator or not. A person is eligible to be a US Representative who is at least 25 years old and has been a US citizen for at least 7 years. Elaborate your program congress.py so it obtains age and length of citizenship and prints out just the one of the following three statements that is accurate: You are eligible for both the House and Senate. You eligible only for the House. You are ineligible for Congress.

Explanation / Answer

Python Code :

#!/usr/bin/python

#Takeing age from the user
age = input('Enter person age ')

#Takeing citizenLength from the user
citizenLength = input('Enter length of citizenship ')

print 'age =',age

print 'citizenLength = ',citizenLength

#checking eligible condition for House and Senate
if age >= 30 and citizenLength >= 9:
print "You are eligible for both the House and Senate."

#checking eligible condition for House
elif age >= 25 and citizenLength >= 7:
print "You eligible only for the House."
else :
print "You are ineligible for Congress."

OUTPUT :

Case 2 :

Enter person age 30
Enter length of citizenship 7
age = 30
citizenLength = 7
You eligible only for the House.
Case 1 :
Enter person age 30
Enter length of citizenship 9
age = 30
citizenLength = 9
You are eligible for both the House and Senate.
Case 3:
Enter person age 20
Enter length of citizenship 5
age = 20
citizenLength = 5
You are ineligible for Congress.
Case 3:
Enter person age 20
Enter length of citizenship 9
age = 20
citizenLength = 9
You are ineligible for Congress.