check for different input python code example

Example 1: python check if input is a number

user_input = input("Enter something:")

if type(user_input) == int:
    return user_input
else:
    print("Not a number")

Example 2: python check if input() gives error

try:
    # Note: Python 2.x users should use raw_input, the equivalent of 3.x's input
    age = int(input("Please enter your age: "))
except ValueError:
    print("Sorry, I didn't understand that.")
else:
	if age >= 18: 
    	print("You are able to vote in the United States!")
	else:
    	print("You are not able to vote in the United States.")