+ 1
Why does the output shows,whatever number I give as input shows as child..
9 Antworten
+ 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!
+ 2
Because your syntax is not proper. It should look like :
if 1 <= Age <= 10:
rather than what you have
+ 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.
+ 1
ABHINAV RAVIKRISH R The first statement will always execute given that the input is a natural number. I hope it helps. Happy coding!
+ 1
Can you elobrate..I couldn't understand
+ 1
Okk..I will try it..thanks
+ 1
ABHINAV RAVIKRISH R I've posted a comment on your code. You may read that for a better understanding on this topic.
0
When I gives the input as 30 it shows child??can anyone give an example for it pls..I couldn't understand correctly
- 1
Or just:
if 0 < Age < 11: ...
as the input is an integer