19 lines
587 B
Python
19 lines
587 B
Python
# Problem 1: Write a Python program to handle a ZeroDivisionError exception when dividing a number by zero
|
|
|
|
def divide(x, y):
|
|
try:
|
|
# try to divide the provided values and store in variable: answer
|
|
answer = x / y
|
|
# print result of division
|
|
print(answer)
|
|
except ZeroDivisionError:
|
|
# handle ZeroDivisionError and prompt user for legal value
|
|
print("Enter a non-zero value")
|
|
|
|
# Instructions: Enter a value to be divided
|
|
dividend = 93
|
|
# and a value to divide by
|
|
divisor = 0
|
|
|
|
#Call the function with defined vars
|
|
divide(dividend, divisor) |