Im trying to make my variable integer input to be only == to an integer, and if its not I want to print and error message. I have put this in a if statement. I always get an error when I input a string instead of my error message.
age = int(input("Enter age:"))
if age != int:
print("Not a number")
解决方案
you have to use raw_input instead of input
if you want this to repeat until you have the correct value you can do this
while True:
try:
age = int(raw_input("Enter age:"))
except ValueError:
print("Not a number")
if age == desired_age: # note I changed the name of your variable to desired_age instead of int
break
I dont recommend you use variable names like int... its generally a bad practice