0

What is wrong in my python code please help!

s=input("Enter your age:") if s < 0: print("no existance") if s < 13: print("child") if s < 18: print("teen") if s < 40: print("adult") if s < 100: print ("old")

21st Dec 2017, 2:42 PM
Chirag Hegde
Chirag Hegde - avatar
7 ответов
+ 11
1. Your input must be converted to int 2. Your indentation is messed up which is wrong in python 3.(optional)Logic is not correct s = int(input("Enter your age:")) if s < 0: print("no existance") elif s < 13 and s >= 0: print("child") elif s < 18 and s >= 13: print("teen") elif s < 40 and s >= 18: print("adult") elif s < 100 and s >= 40: print ("old") else: print("Alien!")
21st Dec 2017, 2:52 PM
Cool Codin
Cool Codin - avatar
+ 2
s=int(input("Your Age:'))
21st Dec 2017, 2:48 PM
Ice
Ice - avatar
0
I tried to nest each statement into each other so that it's a series of checking. like if age<0 is false it will go to age<13 and so on until a condition is satisfied. can you please point out what is wrong in my logic? And also what is crrect indention. Thank you so much btw :)
21st Dec 2017, 2:58 PM
Chirag Hegde
Chirag Hegde - avatar
0
like I just reached the if condition so no idea about 'elif' so is it not possible wihout just if ?
21st Dec 2017, 2:59 PM
Chirag Hegde
Chirag Hegde - avatar
0
s=int((input("Enter your age:")) if s < 0 print("no existance") if s < 13 print("child") if s < 18 print("teen") if s < 40 print("adult") if s < 100 print ("old") implemented the int(input) as you said, but still doesn't work
21st Dec 2017, 4:05 PM
Chirag Hegde
Chirag Hegde - avatar
0
I said just for the first line, you need to use the code @Cool gave.
21st Dec 2017, 4:06 PM
Ice
Ice - avatar
0
yes the input error went away, but still I'm not getting any output :(
21st Dec 2017, 4:07 PM
Chirag Hegde
Chirag Hegde - avatar