Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python code help
#1
So here's the assignment:

Write a program that provides proper output given the following constraints:
• If the person’s age is between 6 and 18 they are told “Remain in school.”
• If the person’s age is 16 or over they are told “You are eligible to drive!”
• If the person’s age is 18 or over they are told “You can vote and/or join the military!”
• If the person’s age is 21 or over they are told “You can drink alcohol too.”
• If the person’s age is 65 to 70 they are told “You are eligible to retire!”
• If the person’s age is the same as the oldest living human, ask “How did you live so long?”
• If the person’s age is greater than the oldest living human or less than zero only “Invalid age was entered.” is displayed.

This is what I have so far:
age = int(input("Enter your age"))

if age >= 6 and age <= 18:
    print("Remain in school")
if age >=16:
    print("You are eligible to drive!")
    if age >= 18:
        print("You can vote and/or join the military!")
    if age >= 21:
        print("You can drink alcohol too.")
    if age >= 65 and age <=70:
        print("You are eligible to retire!")
    if age > 70 and age <=112:
        print("How did you live so long?")
else:
    print("Invalid age was entered.")
I'm having trouble with this code; first issue is when the input is between 6 and 15, I get the output of "Remain in school" and "Invalid age was entered" instead of just the "Remain in school".
The second issue is when the input is > 112 I'm getting "You are eligible to drive!", "You can vote and/or join the military!" and "You can drink alcohol too." How do I get the output to display just "Invalid age was entered."?
Reply


Messages In This Thread
Python code help - by PraiseYAH - Jul-05-2018, 09:12 PM
RE: Python code help - by ichabod801 - Jul-05-2018, 09:58 PM
RE: Python code help - by Zombie_Programming - Jul-05-2018, 10:04 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020