Files
2026-09-13 09:33:20 -04:00

20 lines
819 B
Python

# 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(x, y):
# Try of both numbers that were entered are numbers
try:
x = float(x)
y = float(y)
# Handle the expected ValueError if one of the variables is not a number
except ValueError:
# Raise the TypeError instead of the ValueError
raise TypeError('Enter only numbers')
# Print confirmation message if both values are numbers
else:
print(f'Both {x} and {y} are numbers.')
#Call the numb_check function prompting for two numeric inputs and storing them in x and y vars
numb_check(x = input('Enter a number: '), y = input('Enter another number: '))