Skip to content

Instantly share code, notes, and snippets.

@nikodemusk
Last active August 18, 2018 13:46
Show Gist options
  • Save nikodemusk/776ced15d005b2c882d10d78daff74d1 to your computer and use it in GitHub Desktop.
Save nikodemusk/776ced15d005b2c882d10d78daff74d1 to your computer and use it in GitHub Desktop.
# Validating input in Python
def inputNumber(textOutput):
while True:
try:
userInput = float(input(textOutput)) # or int
except ValueError:
print("This is not a number, try again.")
continue
else:
return userInput
number = inputNumber("Enter any number ->")
print("You entered the number", number)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment