feat: completed problem-01
This commit is contained in:
+10
-3
@@ -1,12 +1,19 @@
|
||||
# Write a Python program to handle a ZeroDivisionError exception when dividing a number by zero
|
||||
|
||||
# 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")
|
||||
|
||||
divide(6, 2)
|
||||
# Instructions: Enter a value to be divided
|
||||
dividend = 93
|
||||
# and a value to divide by
|
||||
divisor = 0
|
||||
|
||||
|
||||
divide(dividend, divisor)
|
||||
Reference in New Issue
Block a user