in part of one program i wanted to ensure that user inputs only so i used:
num=int(raw_input())
while type(num)!= int:
num=int(raw_input('You must enter number only'))
print num
But by doing this , if the user inputted some non-integer like strings or anything else the whole code is displayed error. so how can i make user re-enter the value until they input an integer.
the output was like:
input your number
hdhe
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-4b5e9a275ca4> in <module>()
1 print'input your number'
----> 2 num=int(raw_input())
3 while type(num)!= int:
4 num=int(raw_input('You must enter number only'))
5 print num
ValueError: invalid literal for int() with base 10: 'hdhe'
int()when definingnum:num = raw_input()