dimanche 25 janvier 2015

I want use “isinstance” to judge what type object people input from keyboard


This is my code



num = input()
if not isinstance(num,int):
print("wrong input")
num = input()


However if I type letters from keyboard,the computer gives this error:



please input a num
q
Traceback (most recent call last):
File "ex11.py", line 8, in <module>
num = input()
File "<string>", line 1, in <module>
NameError: name 'q' is not defined




Aucun commentaire:

Enregistrer un commentaire