From 523b96b1520ad9378b0787b0837dd06590494725 Mon Sep 17 00:00:00 2001 From: baphim <269010393+baphim@users.noreply.github.com> Date: Sun, 13 Sep 2026 16:59:38 -0400 Subject: [PATCH] feat: completed problem-08.py --- lab-02/problem-08.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lab-02/problem-08.py b/lab-02/problem-08.py index 906ff22..8ccd6ee 100644 --- a/lab-02/problem-08.py +++ b/lab-02/problem-08.py @@ -1 +1,20 @@ -# Write a Python program that executes division and handles an ArithmeticError exception if there is an arithmetic error \ No newline at end of file +# 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: ')) \ No newline at end of file