Created
August 25, 2014 01:41
-
-
Save troygnichols/e304e64b7ed0269d3ef8 to your computer and use it in GitHub Desktop.
Example of exception handling logic in python
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
#!/usr/bin/env python | |
def get_user_input(): | |
user_input = raw_input("Type in a number: ") | |
print ("You typed: %s") % user_input | |
convert_user_input_to_number(user_input) | |
def convert_user_input_to_number(user_input): | |
try: | |
user_input_as_integer = int(user_input) | |
print ("Looks like you typed a valid number. Good job, buddy!") | |
except: | |
print ("That's not a number, but okay.") | |
get_user_input() | |
get_user_input() | |
print ("Done with this interesting program now. Bye!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment