Someone please explain to my why I'm getting error from this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Someone please explain to my why I'm getting error from this code

QUESTION Given the age of a person as an input, output their age group. Here are the age groups you need to handle: Child: 0 to 11 Teen: 12 to 17 Adult: 18 to 64 Sample Input 42 Sample Output Adult ANSWER age = int(input()) if age<= 11: print("Child") elif age >11 & age <18: print("Teen") elif age >=19 & age <=64: print("Adult")

26th Jul 2022, 6:43 PM
Rebecca
Rebecca - avatar
2 Answers
+ 4
@Felix Instead of using the "&" operator, use "and" Here is an article about the difference between the two: https://www.geeksforgeeks.org/difference-between-and-and-in-JUMP_LINK__&&__python__&&__JUMP_LINK/
26th Jul 2022, 6:54 PM
John Paul Le
+ 3
Felix It's already like John Paul Le but you also have the flaw: elif age >=19 & age <=64: ... That Statement define that someone with 18 isn't a adult, just change 19 to 18. 😉 Hint: When something's inside a former if-statment you don't need to state that the next shouldn't have that values. No Code: If age lesser or equals 11 = Child Else if age bellow 18 = Teen Else if age lesser or equals 64 = Adult
26th Jul 2022, 7:32 PM
Felix Alcor
Felix Alcor - avatar