EXPERIMENT – 1
Aim
To study the concept of Python and develop a simple Python program that uses user input to
display a personalized message.
1. Brief Introduction to Python
Python is a high-level, interpreted programming language known for its simplicity and
readability. It was designed to help programmers write clear and logical code for both small
and large-scale applications.
Python uses a very simple syntax that is easy to learn compared to many other programming
languages such as C or Java. Because of this, Python is often recommended as the first
programming language for beginners.
Python is also a versatile language. It supports multiple programming styles including
procedural programming, object-oriented programming, and functional programming.
Another important aspect of Python is that it is platform independent. This means a Python
program written on one operating system such as Windows can run on Linux or macOS with
little or no modification.
Python has gained massive popularity in recent years due to the rise of data science, artificial
intelligence, and automation. Many companies and organizations use Python for building
software, analyzing data, and developing intelligent systems.
Due to its large community support, Python continues to grow and improve every year.
2. Python Versions
Python has evolved over time with several versions released to improve functionality and
performance.
The language was created by Guido van Rossum and first released in 1991.
There are two major generations of Python:
Python 2
Python 2 was released in the year 2000 and became very popular among developers.
However, it had some design limitations and was officially discontinued in January 2020.
Python 3
Python 3 is the modern and current version of Python. It includes many improvements such as
better memory management, improved Unicode support, and enhanced libraries.
Python 3 is recommended for all new applications and learning purposes.
Some commonly used Python 3 versions include:
Python 3.7
Python 3.8
Python 3.9
Python 3.10
Python 3.11
Each new version introduces improvements, bug fixes, and additional features.
3. Features of Python
Python offers several features that make it one of the most widely used programming
languages in the world.
Easy to Learn
Python has a simple and clean syntax that resembles the English language, making it easier
for beginners to understand.
Interpreted Language
Python code is executed line by line, which helps programmers detect errors quickly and
debug programs easily.
Platform Independent
Python programs can run on different operating systems without major modifications.
Object-Oriented
Python supports object-oriented programming concepts such as classes, objects, inheritance,
and polymorphism.
Large Standard Library
Python provides a rich set of built-in modules and functions that help developers perform
tasks efficiently.
Open Source
Python is freely available and can be modified or distributed by anyone.
Extensible
Python can be integrated with other languages such as C, C++, and Java.
These features make Python suitable for beginners as well as experienced programmers.
4. Python Libraries
One of the biggest advantages of Python is its vast ecosystem of libraries and frameworks.
Libraries are collections of prewritten code that help programmers perform tasks more
efficiently.
Some popular Python libraries include:
Python Libraries
NumPy
NumPy is a library used for numerical and scientific computing in Python. It provides support
for large arrays and matrices along with many mathematical functions. It helps perform
calculations faster and more efficiently. Many other libraries such as Pandas and TensorFlow
depend on NumPy.
Pandas
Pandas is used for data analysis and data manipulation. It provides data structures like Series
and DataFrames to organize data easily. It can read data from files like CSV, Excel, and
databases. It is widely used in data science and analytics.
Matplotlib
Matplotlib is a library used for data visualization. It helps in creating graphs such as line
charts, bar charts, histograms, and pie charts. These visualizations make it easier to
understand patterns and trends in data. It is commonly used with NumPy and Pandas.
TensorFlow
TensorFlow is a machine learning and artificial intelligence library developed by Google. It is
used to build and train deep learning models. It helps computers recognize patterns in data
such as images, speech, and text. TensorFlow is widely used in AI applications.
Django
Django is a high-level Python web framework used to develop web applications quickly. It
provides built-in tools for authentication, database management, and security. Django follows
the Model-View-Template architecture. It helps developers build scalable and secure
websites.
Flask
Flask is a lightweight Python web framework used for small web applications and APIs. It is
simple and flexible compared to Django. Developers can add extensions according to their
needs. Flask is often used for prototypes and small projects.
OpenCV
OpenCV is a library used for image processing and computer vision. It helps computers
understand and analyze images and videos. It is used in applications like face detection, object
recognition, and motion tracking. OpenCV is widely used in AI and robotics projects.
These libraries help developers build complex applications without writing everything from
scratch.
5. Mainly Used In
Python is used in many different industries and domains because of its flexibility and
powerful capabilities.
Web Development
Python frameworks such as Django and Flask are used to build websites and web
applications.
Data Science
Python is widely used for analyzing and visualizing large datasets.
Artificial Intelligence
Many AI and machine learning models are built using Python.
Automation
Python scripts are used to automate repetitive tasks such as file handling, testing, and data
entry.
Software Development
Python is used to build desktop applications and backend systems.
Game Development
Some game engines and prototypes are developed using Python.
Because of these uses, Python has become one of the most demanded programming languages
today.
6. Applications of Python
Python is used in many real-world applications across industries.
Some major applications include:
Web application development
Data analysis and visualization
Artificial intelligence systems
Machine learning models
Automation tools
Scientific computing
Desktop software development
Game development
Cybersecurity tools
Cloud computing services
Many well-known companies use Python in their technology stack, including Google,
Instagram, Netflix, Dropbox, and Spotify.
Python’s flexibility and ease of use make it suitable for both beginners and professional
developers
Program
Code
name = input("Enter your name: ")
age = input("Enter your age: ")
print("Hello", name)
print("You are", age, "years old.")
print("Welcome to Python Programming.")
Output
Enter your name: Aakash
Enter your age: 20
Hello Aakash
You are 20 years old.
Welcome to Python Programming.
Result
Thus the Python program to display a personalized message using user input was executed
successfully.
EXPERIMENT 2
Aim
To write a Python program that asks the user's age and determines whether the person is
eligible to vote in the next election.
Theory
Conditional statements allow a program to make decisions based on conditions.
Python provides the following conditional statements:
if
if-else
if-elif-else
These statements check whether a condition is true or false.
Example:
if condition:
statement
else:
statement
In this program, the age entered by the user is checked.
If the age is 18 or above, the person can vote.
Otherwise, the person is not eligible.
Code
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
Output
Example 1
Enter your age: 20
You are eligible to vote.
Example 2
Enter your age: 16
You are not eligible to vote.
Result
Thus the Python program to check voting eligibility using conditional statements was
executed successfully.
EXPERIMENT 3
Aim
To write a Python program to calculate the factorial of a number using a loop.
Theory
Loops are used to repeat a block of code multiple times.
Python provides two main types of loops:
for loop
while loop
A factorial of a number is the product of all positive integers less than or equal to the number.
Example:
5! = 5 × 4 × 3 × 2 × 1 = 120
Loops are useful when performing repeated calculations such as factorial.
Code
num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
fact = fact * i
print("Factorial of", num, "is", fact)
Output
Enter a number: 5
Factorial of 5 is 120
Result
Thus the Python program to find the factorial of a number using a loop was executed
successfully.
EXPERIMENT – 4
Aim
To write a Python program that prompts the user to enter a list of numbers and sorts them in
ascending order.
Theory
A list in Python is a collection of items stored in a single variable. Lists are ordered and
changeable, meaning elements can be modified after creation. Lists allow duplicate values
and can store different data types such as numbers, strings, or mixed values.
Lists are created using square brackets [ ].
Python provides many built-in functions to work with lists such as append(), insert(),
remove(), pop(), and len().
Lists are widely used in programs where multiple values need to be stored and processed
together.
Example of a list:
numbers = [10, 20, 30, 40]
Lists make programs more organized and efficient when handling large amounts of data.
Code
numbers = [10, 20, 30, 40]
print("Original List:", numbers)
[Link](50)
print("After Adding Element:", numbers)
[Link](20)
print("After Removing Element:", numbers)
print("Length of List:", len(numbers))
Output
Original List: [10, 20, 30, 40]
After Adding Element: [10, 20, 30, 40, 50]
After Removing Element: [10, 30, 40, 50]
Length of List: 4
Result
Thus the Python program to create and perform operations on a list was executed
successfully.