Skip to content

Instantly share code, notes, and snippets.

@telmotrooper
Last active March 7, 2016 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telmotrooper/5ff7c9b2909c5bc2d313 to your computer and use it in GitHub Desktop.
Save telmotrooper/5ff7c9b2909c5bc2d313 to your computer and use it in GitHub Desktop.
Guarantees that the user input respects the specified built-in type.
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