py01
py01
1
Program to perform arithmetic operations by accepting
values from users
Date of Performance:8/1/25
Date of Submission:17/1/25
Experiment No. 1
Aim: To write a program to perform arithmetic operations by accepting values from users
Theory:
What is Python?
Python is a popular programming language. It was created by Guido van Rossum, and released
in 1991.
It is used for:
Why Python?
● Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
● Python has a simple syntax similar to the English language.
● Python has syntax that allows developers to write programs with fewer lines than some
other programming languages.
● Python runs on an interpreter system, meaning that code can be executed as soon as it is
written. This means that prototyping can be very quick.
● Python can be treated in a procedural way, an object-oriented way or a functional way.
Good to know
● The most recent major version of Python is Python 3, which we shall be using in this
tutorial. However, Python 2, although not being updated with anything other than security
updates, is still quite popular.
● In this tutorial Python will be written in a text editor. It is possible to write Python in an
Integrated Development Environment, such as Thonny, Pycharm, Netbeans or Eclipse
which are particularly useful when managing larger collections of Python files.
● Python was designed for readability, and has some similarities to the English language
with influence from mathematics.
● Python uses new lines to complete a command, as opposed to other programming
languages which often use semicolons or parentheses.
● Python relies on indentation, using whitespace, to define scope; such as the scope of
loops, functions and classes. Other programming languages often use curly-brackets for
this purpose.
Arithmetic operators are used to perform mathematical operations like addition, subtraction,
multiplication and division.
There are 7 arithmetic operators in Python:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modulus
6. Exponentiation
7. Floor division
CODE:
print("Select operation:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Modulus (Remainder)")
print("6. Exponentiation (Power)")
print("7. Floor Division")
if choice == '1':
result = num1 + num2
print(f"The result of addition is: {result}")
elif choice == '2':
result = num1 - num2
print(f"The result of subtraction is: {result}")
elif choice == '3':
result = num1 * num2
print(f"The result of multiplication is: {result}")
elif choice == '4':
if num2 != 0:
result = num1 / num2
print(f"The result of division is: {result}")
else:
print("Division by zero is not allowed.")
elif choice == '5':
if num2 != 0:
result = num1 % num2
print(f"The result of modulus is: {result}")
else:
print("Division by zero is not allowed for modulus.")
elif choice == '6':
result = num1 ** num2
print(f"The result of exponentiation is: {result}")
elif choice == '7':
if num2 != 0:
result = num1 // num2
print(f"The result of floor division is: {result}")
else:
print("Division by zero is not allowed for floor division.")
else:
print("Invalid choice. Please select a valid operation.")
OUTPUT:
Conclusion:
This program is useful in real-world scenarios like billing systems, financial calculators, and
scientific computations, where users need to perform arithmetic operations dynamically. It
helps in automating calculations in applications such as banking, retail, and data analysis.