+ 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")
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/
+ 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