From d271ab4b4b3bdbca91ad55354652abdd0135cc64 Mon Sep 17 00:00:00 2001 From: baphim <269010393+baphim@users.noreply.github.com> Date: Sun, 13 Sep 2026 08:48:37 -0400 Subject: [PATCH] feat(problem-04.py): completed problem --- lab-02/problem-04.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lab-02/problem-04.py b/lab-02/problem-04.py index f73fbfc..af01474 100644 --- a/lab-02/problem-04.py +++ b/lab-02/problem-04.py @@ -1,15 +1,22 @@ # Write a Python program that prompts the user to input two numbers and raises a TypeError exception if the inputs are # not numerical. +# Define the function to check if user input is a number def numb_check(n): - while True: - try: - numb = float(input(n)) - except ValueError: - print(f"{numb} is not a number") - + # Try if input is number and store in numb variable + try: + numb = float(n) + # Return the stored number + return numb + except ValueError: + # Handle a non-numeric input as to pass it on to the * operation + print('Enter only numbers...') +# Call the function and store the input in x variable x = numb_check(input('Enter a number: ')) +# Call the function and store this input in y variable y = numb_check(input('Enter another number: ')) +# Multiply the two inputs as to raise a TypeError if input is non-numeric product = x * y -print(product) \ No newline at end of file +# Print the product of the multiplication +print(f'{x} multiplied by {y} is {product}') \ No newline at end of file