1whatever = input("Pick an integer > ")
2 try:
3 whatever_as_an_integer = int(whatever)
4 print("That was an integer.")
5
6 except ValueError:
7 print("That is not an integer.")
1user_input = input("Enter something:")
2
3if type(user_input) == int:
4 return user_input
5else:
6 print("Not a number")
1whatever = input("Pick an integer > ")
2try:
3 whatever_as_an_integer = int(whatever)
4 print("That was an integer.")
5
6except ValueError:
7 print("That is not an integer.")
1user_input = input("Enter Something:")
2
3if user_input.isnumeric():
4 print("Is a number")
5else:
6 print("Is not a number")
1def check_user_input(input):
2 try:
3 # Convert it into integer
4 val = int(input)
5 print("Input is an integer number. Number = ", val)
6 except ValueError:
7 try:
8 # Convert it into float
9 val = float(input)
10 print("Input is a float number. Number = ", val)
11 except ValueError:
12 print("No.. input is not a number. It's a string")
1user_input = input("Enter something:")
2
3if type(user_input) == int:
4 print("Is a number")
5else:
6 print("Not a number")