Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python code help
#2
Look at your conditionals and follow the numbers through.

If you enter 8, it trips the first conditional, but not the second conditional, so the else is triggered. The else clause only cares about the most recent if clause (the second one). A solution here would be to change else to elif age > 112, or if age > 112 if you haven't covered elif yet.

If you enter 120, that is greater than 112, so it triggers the second if clause, which means the else is not triggered. So you need to change the if clause to prevent that.

Two things to note: You have not covered the situation of an age less than zero. That means you probably want to make the else clause into an if clause. Second, these two are equivalent:

if age > 70 and age <=112:
    print("How did you live so long?")
if 70 < age <=112:
    print("How did you live so long?")
It's called chaining your comparisons.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
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