How do I check if a user's string input is a number (e.g.
user_input = input("Enter something:") if type(user_input) == int: print("Is a number") else: print("Not a number")
The above won't work since
input always returns a string.
Simply try converting it to an int and then bailing out if it doesn't work.
try: val = int(userInput) except ValueError: print("That's not an int!")
Apparently this will not work for negative values, but it will for positive. Sorry about that, just learned about this a few hours ago myself as I have just recently gotten into Python.
if userinput.isdigit(): #do stuff