0% found this document useful (0 votes)
38 views2 pages

Assignment No 6

The document contains a Python function that performs arithmetic by prompting the user to input two numbers, adds them, and prints the result. It includes error handling for invalid inputs and type errors. The function is executed at the end of the document.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

Assignment No 6

The document contains a Python function that performs arithmetic by prompting the user to input two numbers, adds them, and prints the result. It includes error handling for invalid inputs and type errors. The function is executed at the end of the document.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Code:

def perform_arithmetic():
try:
num1 = input("Enter the first number: ")
num2 = input("Enter the second number: ")

num1 = float(num1)
num2 = float(num2)

result = num1 + num2

if not isinstance(result, (int, float)):


raise TypeError("The result is not a numerical value.")

print(f"The result of adding {num1} and {num2} is: {result}")

except ValueError:
print("Invalid input! Please enter valid numbers.")
except TypeError as te:
print(f"Type error: {te}")
perform_arithmetic()

OUTPUT:-

You might also like