feat: completed problem-08.py
This commit is contained in:
@@ -1 +1,20 @@
|
||||
# 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: '))
|
||||
Reference in New Issue
Block a user