0
Boleean 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 Here's my code: age = int(input()) teen = 17 adult = 18 if age < teen or age < adult: print("Teen") else: print("Adult") I don't know where did go wrong.
6 Answers
+ 5
sword saint
You put Teen as 17 not 12
and only 2 age catagories Teen & Adult forgetting about Children ..
age = int(input())
teen = 12
adult = 18
if age >= teen and age < adult:
print("Teen")
elif age >= adult and age <= 64:
print("Adult")
else:
print("Child")
+ 4
Here's a rough condition template you should have done:
Child: 0 to 11 | age <= 11;
Teen: 12 to 17 | age > 11 and age < 18;
Adult: 18 to 64 | age > 17 and age < 65;
Here's what you can get out of it ☺️:
age = int(input()or 17)
Child = age <= 11
Teen = age > 11 and age < 18
Adult = age > 17 and age < 65
if Child: print('Child')
if Teen: print('Teen')
if Adult: print('Adult')
You need to learn how to translate from a human language into a programming language and there will be no problems with writing codes ☺️.
And here is how the code will look if you use the list() and range() functions ☺️:
age = int(input()or 17)
Child = list(range(12))
Teen = list(range(12,18))
Adult = list(range(18,65))
if age in Child: print('Child')
if age in Teen: print('Teen')
if age in Adult: print('Adult')
+ 3
sword saint
What about to print Child?
what if age is 10?
10 < 17 would be Teen which should not be
+ 2
I wasn't even close lmaoo
+ 2
Axel_ спасибо, рад был помочь.
Удачного кодирования!
+ 1
Vasiliy никогда не видел такого подхода к реализации множественных сравнений — особенно последний пример. Это выглядит изощренно, но круто, спасибо за новый опыт!