Created
February 9, 2021 16:38
-
-
Save azamsharp/f31601db3cab87f76220d0049b932f4d 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
# EXCEPTIONS | |
# try and except go together | |
try: | |
result = 1/2 | |
number = int(input("Enter any number: ")) # e | |
except ZeroDivisionError: | |
print("Please don't divide by zero!") | |
except ValueError: | |
print("Invalid input. Please enter numbers only!") | |
except: | |
print("Opps!!") | |
# finally is an optional block which executes whether exception takes place or NOT | |
finally: | |
# finally block is where to close out the resources | |
print("FINALLY!") | |
else: # optional block. Fired when no exceptions are thrown | |
print("ELSE BLOCK") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment