-1

If created this program to only print when the condition is equivalent to the variable age which should've resulted in the final statement to be printed however once I ran the program it instead printed the second last statement which prints out close instead of perfect. I've to figure it out but I couldn't

age = 7
if age == 9:
    print('too old')
elif age == 5:
    print('too young')
elif age == 6 or 8:
    print('close')
elif age == 7:
    print('yes, perfect')
James Powis
  • 609
  • 4
  • 16

2 Answers2

0

8 is truthy.

try this:

age = 7
if age == 9:
    print('too old')
elif age == 5:
    print('too young')
elif age == 6 or age == 8:
    print('close')
elif age == 7:
    print('yes, perfect')
James Powis
  • 609
  • 4
  • 16
0

you must repeat the condition when using "or"

age = 7
if age ==9:
    print('too old')
elif age ==5:
    print('too young')
elif age == 6 or age == 8:
    print('close')
elif age==7:
    print('yes, perfect')
Ro0t
  • 179
  • 8