I\'ve written the following code in Python 3.x to validate the user\'s input:
while True:
try:
answer = int(input(\"Enter an integer: \"))
except
You can do this without relying on an exception using isdigit():
answer = input("Enter an integer: ")
while not answer.isdigit():
print("That's not a whole number. Try again.")
answer = input("Enter an integer: ")
answer = int(answer)
isdigit() tests to see if the input string is made up entirely of numbers that can be converted with int().