+ 1
I want to create age groups but my code isn't working
age = int(input()) if 0<=age>=11: print("child") elif 12<=age>=17 print("Teen") elif 18<=age>=64 print("Adult")
3 Answers
+ 6
Age should be greater than one value and less than other value.
Also, c needs to be uppercase in Child
+ 5
josef stalin,
if your question refers to "python core exercise 21.3" , we also need to capture "Senior"
there are some issue to solve:
age = int(input())
if 0 <= age <= 11: # was incorrect condition
print("Child")
elif 12 <= age <= 17: # was missing colon, incorrect condition
print("Teen")
# ... complete the missing code...
# age groups:
Child: 0 to 11
Teen: 12 to 17
Adult: 18 to 64
Senior: 65+
+ 2
Review the logic. The comparison operators are wrong. For instance,
if 0<=age>=11:
Let's try age=12.
Is age>=0? (True), and is age>=11? (True). So it prints "child", which is not what you wanted. Correct it to say:
if 0<=age<=11:
Now fix the rest of the code.