I want to create age groups but my code isn't working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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")

17th Feb 2022, 10:48 AM
josef stalin
3 Answers
+ 6
Age should be greater than one value and less than other value. Also, c needs to be uppercase in Child
17th Feb 2022, 10:52 AM
Simba
Simba - avatar
+ 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+
17th Feb 2022, 6:40 PM
Lothar
Lothar - avatar
+ 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.
17th Feb 2022, 6:45 PM
Brian
Brian - avatar