Files
2026-09-13 16:59:38 -04:00

20 lines
755 B
Python

# Write a Python program that executes division and handles an ArithmeticError exception if there is an arithmetic error
# Define the 'divide' function to divide user entered value 'x' by 'y'
def divide(x, y):
# Cast entered variables as floating-point numbers
x = float(x)
y = float(y)
# Try the division operation
try:
answer = x / y
# Print the result of the division operation
print(answer)
# Handle an ArithmeticError if one occurs
except ArithmeticError:
# Print error message
print('The operation can not be completed')
# Call the function and prompt user to enter values for x and y
divide(x = input('Enter a value to be divided: '), y = input('Enter a value to divide by: '))