0% found this document useful (0 votes)
3 views

py01

The document outlines an experiment to create a Python program that performs basic arithmetic operations based on user input. It introduces Python's capabilities, syntax, and arithmetic operators, providing a sample code for implementation. The program is applicable in various real-world scenarios such as billing systems and financial calculators.
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)
3 views

py01

The document outlines an experiment to create a Python program that performs basic arithmetic operations based on user input. It introduces Python's capabilities, syntax, and arithmetic operators, providing a sample code for implementation. The program is applicable in various real-world scenarios such as billing systems and financial calculators.
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
You are on page 1/ 5

Experiment No.

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

Title: Program to perform arithmetic operations by accepting values from users

Aim: To write a program to perform arithmetic operations by accepting values from users

Objective: To introduce basic concepts in Python

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:

●​ web development (server-side),


●​ software development,
●​ mathematics,
●​ system scripting.

What can Python do?

●​ Python can be used on a server to create web applications.


●​ Python can be used alongside software to create workflows.
●​ Python can connect to database systems. It can also read and modify files.
●​ Python can be used to handle big data and perform complex mathematics.
●​ Python can be used for rapid prototyping, or for production-ready software development.

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 Syntax compared to other programming languages

●​ 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:

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))

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")

choice = input("Enter your choice (1/2/3/4/5/6/7): ").strip()

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.

You might also like