0% found this document useful (0 votes)
24 views1 page

Python Program for Basic Arithmetic

The document outlines a Python program that reads two numbers from the user and performs arithmetic operations based on the user's choice. The operations include addition, subtraction, multiplication, and division, with error handling for division by zero. It prompts the user to select an operation and displays the result accordingly.

Uploaded by

ecobliss22
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

Python Program for Basic Arithmetic

The document outlines a Python program that reads two numbers from the user and performs arithmetic operations based on the user's choice. The operations include addition, subtraction, multiplication, and division, with error handling for division by zero. It prompts the user to select an operation and displays the result accordingly.

Uploaded by

ecobliss22
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. a.

Develop a python program to read 2 numbers from the keyboard and perform the
arithmetic operations based on the choice. (1-Add, 2-Subtract, 3-Multiply, 4-Divide)

num1 = int(input("Enter first number: "))


num2 = int(input("Enter second number: "))

print("\nChoose an operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")

choice = int(input("Enter your choice (1-4): "))

if choice == 1:
result = num1 + num2
print("The sum is:", result)
elif choice == 2:
result = num1 - num2
print("The difference is:",result)
elif choice == 3:
result = num1 * num2
print("The product is:",result)
elif choice == 4:
if num2 != 0: # to avoid divide by zero error
result = num1 / num2
print("The division is:",result)
else:
print("Error! Division by zero is not allowed.")
else:
print("Invalid choice! Please enter a number between 1 and 4.")

You might also like