#quote from MIT 'introduction to computation and programming using python, Revised'
def readVal(valType, requestMsg, errorMsg):
while True:
val = raw_input(requestMsg + ' ')
try:
val = valType(val)
return val
except ValueError:
print val, errorMsg
n = readVal(int, 'Enter an integer:', 'is not an integer.')
print n
%run "C:\Users\Administrator\test.py"
Enter an integer: hello
hello is not an integer.
Enter an integer: 12.99
12.99 is not an integer.
Enter an integer: 34
34