Skip to content

Instantly share code, notes, and snippets.

@lakshay-arora
Created April 9, 2020 07:44
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 lakshay-arora/a5da2660732d3f90e69919f032db9b0f to your computer and use it in GitHub Desktop.
Save lakshay-arora/a5da2660732d3f90e69919f032db9b0f to your computer and use it in GitHub Desktop.
# define a function to divide two numbers
def division(a, b):
# use the try statement where error may occur
try:
print(a/b)
# if the error occurs, handle it !!
except ZeroDivisionError:
print("Cannot divide by Zero!!")
else:
print("No Error occured!!")
finally:
print('Value of a', a, 'and b', b)
division(10,0)
## >> Cannot divide by Zero!!
## >> Value of a 10 and b 0
division(10,2)
## >> 5.0
## >> No Error occured!!
## >> Value of a 10 and b 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment