please bare in mind i'm not great at python and i am tying to improve
i'm not a python genius so i need help with this. I need the outcome of an 'if' statement to be determined by the data type of a user's input. wheres what i'v got:
x=input("enter something: ")
if type(x) == int:
print("x is an int")
else:
print("x is not an int")
If i enter an int the output is "x is an int", which works fine, but if i enter a string (such as 'a') i get the an error:
File "<string>", line 1, in <module>
NameError: name 'a' is not defined
i would like the code to work despite what data type i use, thank you.
Aucun commentaire:
Enregistrer un commentaire