+ 1

Why does the output shows,whatever number I give as input shows as child..

https://code.sololearn.com/cdnRue5Uwkt1/?ref=app

16th Aug 2021, 4:28 AM
ABHINAV RAVIKRISH R
ABHINAV RAVIKRISH R - avatar
9 Respuestas
+ 1
ABHINAV RAVIKRISH R Here are two codes that might help: #1 age = int(input()) if 0 < age < 11: print("child") elif 10 < age < 21: print("whatever") elif 20 < age < 31: print("adult") else: print("Not acceptable") #2 if age > 30 or age < 1: print("Not acceptable") elif age > 20: print("adult") elif age > 10: print("whatever") else: print("child") # Hope this helps # Happy coding!
16th Aug 2021, 5:13 AM
Calvin Thomas
Calvin Thomas - avatar
+ 2
Because your syntax is not proper. It should look like : if 1 <= Age <= 10: rather than what you have
16th Aug 2021, 4:38 AM
David Akhihiero
David Akhihiero - avatar
+ 2
Okay. This line: if Age >= 1 <= 10 will always evaluate as True as long as Age is greater than or equal to 1. Age >= 1 is True (i.e "1") and since 1 is always less than 10, the statement is True.
16th Aug 2021, 4:42 AM
David Akhihiero
David Akhihiero - avatar
+ 1
ABHINAV RAVIKRISH R The first statement will always execute given that the input is a natural number. I hope it helps. Happy coding!
16th Aug 2021, 4:37 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Can you elobrate..I couldn't understand
16th Aug 2021, 4:39 AM
ABHINAV RAVIKRISH R
ABHINAV RAVIKRISH R - avatar
+ 1
Okk..I will try it..thanks
16th Aug 2021, 4:42 AM
ABHINAV RAVIKRISH R
ABHINAV RAVIKRISH R - avatar
+ 1
ABHINAV RAVIKRISH R I've posted a comment on your code. You may read that for a better understanding on this topic.
16th Aug 2021, 4:43 AM
Calvin Thomas
Calvin Thomas - avatar
0
When I gives the input as 30 it shows child??can anyone give an example for it pls..I couldn't understand correctly
16th Aug 2021, 4:44 AM
ABHINAV RAVIKRISH R
ABHINAV RAVIKRISH R - avatar
- 1
Or just: if 0 < Age < 11: ... as the input is an integer
16th Aug 2021, 4:42 AM
Calvin Thomas
Calvin Thomas - avatar