Last active
March 7, 2016 20:29
-
-
Save telmotrooper/5ff7c9b2909c5bc2d313 to your computer and use it in GitHub Desktop.
Guarantees that the user input respects the specified built-in type.
This file contains hidden or 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
def input_float(msg): | |
while True: | |
try: | |
return float(input(msg)) | |
except ValueError: | |
print("The input value is not a float.") | |
def input_int(msg): | |
while True: | |
try: | |
return int(input(msg)) | |
except ValueError: | |
print("The input value is not an integer.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment