In: Computer Science
1) Create a "Can I be President?" program. The program determines if the user meets the minimum requirements for becoming the President of the United States. Use user input. The rules for being president of the U.S. are:
Older than 35
Resident of US for 14 Years
Natural born citizen
Print True if the person could be president and False if they can't be president. 2) Alter one line of that program to be a "I can't be President?" game. Print True if the user cannot be President and False if they can be President.
print('How old are you?')
age = int(input())
if age >= 35:
print('you qualify')
else:
print('you do not qualify')
print('How long have you lived in the U.S.?')
resident = int(input())
if resident >= 14:
print('You qualify')
else:
print('You do not qualify')
print('Are you a born citizen?')
citizen = str(input())
if citizen == "Yes":
print('You qualify')
else:
print('You do not qualify')
if age >= 35 and resident >= 14 and citizen ==
"Yes":
print("True")
else:
print("False")
Hello, I did the program, but does this look correct? How do I answer question 2? Feel free to edit, but please keep my variables
(1.) Yes, your code is working fine, and it generates the correct output for the question asked in part 1, the screenshot of your python code for the part 1 run on an online compiler is as follows:-
(2.) The part 2 is asking the opposite of part 1, the code will remain same except the last if condition in which we will check whether the person meets any of the criteria of "I can't be president", if he meets then print True otherwise print False, please note that here I am editing your code given in the question so that it will help you to understand, the python code is as follows:-
print('How old are you?')
age = int(input())
if age >= 35:
print('you qualify')
else:
print('you do not qualify')
print('How long have you lived in the U.S.?')
resident = int(input())
if resident >= 14:
print('You qualify')
else:
print('You do not qualify')
print('Are you a born citizen?')
citizen = str(input())
if citizen == "Yes":
print('You qualify')
else:
print('You do not qualify')
if age < 35 or resident < 14 or citizen != "Yes": # only this
line will change
print("True")
else:
print("False")
The output of the above code is as follows:-
How old are you?
34
you do not qualify
How long have you lived in the U.S.?
12
You do not qualify
Are you a born citizen?
Yes
You qualify
True
The screenshot of the above code is as follows:-