What is the error? (Simple If Else Question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the error? (Simple If Else Question

Everything I try results in a error. No matter, if I try flif, else if or anything else. It says that line 5 has a error. Could you help me out with that? And please with explanation I want to learn. Thank you! <3 age = int(input()) if age <= 11: print("Child") elif age >= 12 and age < 18: print("Teen") elif age <= 64 and > 18: print("Adult") elif age > 64: print("Senior")

4th Sep 2021, 12:50 PM
Deniz Lier
Deniz Lier - avatar
7 Answers
+ 1
You where on the right way. But only the word "age" Was missing. Look at this: age = int(input()) if age <= 11: print("Child") elif age >= 12 and age < 18: print("Teen") elif age <= 64 and age > 18: print("Adult") elif age > 64: print("Senior") ... AGE <= 64 and AGE > 18:
4th Sep 2021, 1:14 PM
Coding Cat
Coding Cat - avatar
+ 4
elif age <= 64 and > 18: ??? Should it be: elif age <= 64 and age > 18
4th Sep 2021, 12:58 PM
Coding Cat
Coding Cat - avatar
+ 3
Coding Cat [Mouse searching] age = int(input()) if age <= 11: print("Child") else if: age >= 12 and age < 18 print("Teen") else if age <= 64 and > 18 print("Adult") else if age > 64: print("Senior") Now I removed the ":" after every statement, but it still show me a Syntax error in line 5
4th Sep 2021, 1:04 PM
Deniz Lier
Deniz Lier - avatar
+ 3
Looks like you have > 18 and < 18. What happens if someone input is 18.
4th Sep 2021, 1:06 PM
Paul
Paul - avatar
+ 2
No, dont remove the colon. But add the word "age"
4th Sep 2021, 1:05 PM
Coding Cat
Coding Cat - avatar
+ 2
Coding Cat [Mouse searching] Thank you so much!!! I tried so long to fix this bug.. such a simple mistake. I'll try to prevent myself from doing this mistake again Also thank you to Paul ! You are so right something I didn't think of thank you
4th Sep 2021, 2:47 PM
Deniz Lier
Deniz Lier - avatar
+ 1
And Paul is also right. Your condition for Adult should be age >= 18 !! Not only >18. Because if you only check <18 and >18, you get no result for age = 18.
4th Sep 2021, 1:22 PM
Coding Cat
Coding Cat - avatar