0% found this document useful (0 votes)
2 views3 pages

Program 1

The document outlines a Python program designed to perform various arithmetic operations on two user-input numbers. It includes error handling for invalid inputs and division by zero. The program performs addition, subtraction, multiplication, division, floor division, modulo, and exponentiation, displaying the results accordingly.

Uploaded by

Karthik S
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)
2 views3 pages

Program 1

The document outlines a Python program designed to perform various arithmetic operations on two user-input numbers. It includes error handling for invalid inputs and division by zero. The program performs addition, subtraction, multiplication, division, floor division, modulo, and exponentiation, displaying the results accordingly.

Uploaded by

Karthik S
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.

ARITHMETIC OPERATIONS

Aim:
To create a python program to perform different Arithmetic Operations.

Algorithm:
Step 1: Start the process.
Step 2: Use the input() function to read two numbers as input from the user.
Step 3: Use the int() function to convert the input from string to integer type.
Step 4: Display an appropriate error message if the user enters invalid input.
Step 5: Use the arithmetic operators +, -, *, /, //, % and ** to perform the addition,
subtraction, multiplication, division, floor division, modulo and exponentiation operations.
Step 6: Display an appropriate error message if the division by 0 error occurs in the program.
Step 7: Save the program and display the result.

Program:
try:
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
except ValueError:
print("Invalid input. Please enter numeric values.")
print(f"\nPerforming Arithmetic operations with {num1} and {num2}:")

# Addition Operation
sum=num1+num2
print(f"Addition: {num1} + {num2} = {sum}")

# Subtraction Operation
difference=num1-num2
print(f"Subtraction: {num1} - {num2} = {difference}")
# Multiplication Operation
product=num1*num2
print(f"Multiplication: {num1} * {num2} = {product}")

# Division Operation
if num2 != 0:
quotient1=num1/num2
print(f"Division: {num1} / {num2} = {quotient1}")
else:
print("Division by zero is not allowed.")

# Floor Division Operation


if num2 != 0:
quotient2=num1//num2
print(f"Floor Division: {num1} // {num2} = {quotient2}")
else:
print("Floor division by zero is not allowed.")

# Modulo Operation
if num2 != 0:
remainder=num1%num2
print(f"Modulo: {num1} % {num2} = {remainder}")
else:
print("Modulo by zero is not allowed.")

# Exponentiation Operation
exponent=num1**num2
print(f"Exponentiation: {num1} ** {num2} = {exponent}")
Output:
Enter the first number: 8
Enter the second number: 2

Performing Arithmetic operations with 8 and 2:


Addition: 8 + 2 = 10
Subtraction: 8 - 2 = 6
Multiplication: 8 * 2 = 16
Division: 8 / 2 = 4.0
Floor Division: 8 // 2 = 4
Modulo: 8 % 2 = 0
Exponentiation: 8 ** 2 = 64

You might also like