You can write a function which inputs a number and then converts it to an int, but doesn't work if it is anything else. If I understand you right, you only want the user to be able to enter an int but not a string. If you only want to check that, an example is:
def prompt (message):
try:
choice = int(input(message))
return choice
except ValueError:
print("That is not a valid answer, please try again.")
return prompt(message)
That's generally how I do it, but you can definitely use a while loop if you want.
Edit: This allows you to define the choices you want:
def prompt (message, choices):
try:
choice = int(input(message))
if choice in choices:
return choice
else:
print("Not a valid input, please try again. \n",
"Valid inputs are:", (choices))
return prompt(message, choices)
except ValueError:
print("Not a valid input, please try again. \n",
"Valid inputs are:", choices)
return prompt(message, choices)