Last active
August 18, 2018 13:46
-
-
Save nikodemusk/776ced15d005b2c882d10d78daff74d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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