0
Beginner python question
having trouble with this 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 code that I wrote: age = int(input()) if age>=0 and age<=11: print("Child") elif age>=12 and age<=17: print("Teen") elif age>=18 and age<=64: print("Adult") the error i keep getting: File "/usercode/file0.py", line 4 elif age>=12 and age<=17: ^ SyntaxError: invalid syntax I've tried it using else instead of elif still coming with a similar error any help would be much appreciated. Thank you!!
3 Respuestas
+ 3
Please see the way of writing the if-elif statement
It's the syntax
if condition:
#your code
elif condition:
#your code
At first you have to write "if" then you can proceed with "elif", I strongly prefer you to search about "nested if statements" in Python for more information.
Solution is given above by ㅤㅤㅤ
Happy Learning 🙂
+ 2
Your code has some indentation errors, learn about indentation, rest of the code is right👍
Here is your corrected code:
//
age = int(input())
if age>=0 and age<=11:
print("Child")
elif age>=12 and age<=17:
print("Teen")
elif age>=18 and age<=64:
print("Adult")
0
Thank you guys appreciate the help I think I understand where I went wrong