I\'ve written a small program in Python which determines if a person is 18 years
ID: 3629335 • Letter: I
Question
I've written a small program in Python which determines if a person is 18 years or older and be able to vote. It also includes an additional statement for persons over the age of 64 years old.My question is: I only want the (1) statement to appear after the user keys in the age for 64 or older. Presently 2 statements appear, I don't not both statements. What Python coding will make just the one statement appear exclusively for persons over 64 years old?
Python v3.2 Code Posted Here:
_________________________________________________________________________
# This program calculates if a person is old enough to vote at age 18, in the year 2011.
# Written by - Richard Gatewood, September 27, 2011.
Greeting1 = print ("Hello, lets determine if you're of legal voting age ...")
age = input("Type in your age number as of today, and press ENTER: ")
age = int(age)
result1 = (2011-age-1)
result2 = (2011-age-1)
# Statement for persons 64 years and older.
if result2 < 1947:
print ("You're a Senior Citizen .. you deserve 2 votes!")
# Statement for persons 18-63 years old.
if result1 < 1993:
print ("Yes - you're old enough to vote.")
# Statement for persons 17 years and younger.
else:
print ("No - you're just too young to vote right now.")
quit
Explanation / Answer
You need to add the elif statement which is like else if meaning if the first stament is true then don't exicute the second statement
# This program calculates if a person is old enough to vote at age 18, in the year 2011.
# Written by - Richard Gatewood, September 27, 2011.
Greeting1 = print ("Hello, lets determine if you're of legal voting age ...")
age = input("Type in your age number as of today, and press ENTER: ")
age = int(age)
result1 = (2011-age-1)
result2 = (2011-age-1)
# Statement for persons 64 years and older.
if result2 < 1947:
print ("You're a Senior Citizen .. you deserve 2 votes!")
# Statement for persons 18-63 years old.
elif result1 < 1993:
print ("Yes - you're old enough to vote.")
# Statement for persons 17 years and younger.
else:
print ("No - you're just too young to vote right now.")
quit
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.