+ 1
Python n00b-please help! - if-else script
hi all, I can't figure out how to specify the user input I'm asking for to be type integer so I can run the rest of the if/ else piece: i = input("please provide a number that you like") input=type("int") if i <=5: print(i) else: print("whoa thats greater than 5!") print("Let me make that smaller for you:") i= i - 3 print(i) print("There,now that's better , take it easy fella!")
7 Answers
+ 3
Try this:
i = int(input("please provide a number that you like"))
if i <= 5:
print(i)
else:
print("whoa thats greater than 5!")
print("Let me make that smaller for you:")
i= i - 3
print(i)
print("There,now that's better , take it easy fella!")
+ 2
if you want to specify the input type as an integer, just wrap it as an int
i = int(input("Please provide a number that you like"))
+ 1
I don't know Python's syntax, so I speak abstract
i = input
if is int(i) == false:
raise TypeError: Given value must be an instance of integer, type(i) given.
+ 1
Then use 'try-except' block to check if any of exceptions is raised. You can lesrn more in SL course
0
Raise an exception.
0
Thank you very much for the reply. How exactly would I do that?
0
Thanks guys!