Hey just starting to learn python and got some problems already I made a code with an if statement It should work but it isn\'t working can someone fix it and tell me what I did
You have convert it to an int
. raw_input
gives you a string.
x= raw_input("Enter your name: ")
y= raw_input("Enter your grade: ")
print(y)
if 50 <= int(y) <= 100:
print("Good input")
else:
print ("Invaild input")
But what if the user does not enter a number, then you need to add a Try-Except block:
x = raw_input("Enter your name: ")
y = raw_input("Enter your grade: ")
print(y)
try:
if 50 <= int(y) <= 100:
print("Good input")
else:
print ("Invaild input")
except ValueError:
print "You did not enter a number for your grade"