Python Practical Programs (Ready to Print)
Name: __
Class & Section: _
Subject: Computer Applications / Informatics Practices
Teacher: ___
1. Program to add the elements of two lists
Aim: To add corresponding elements of two lists.
list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]
result = []
for i in range(len(list1)):
[Link](list1[i] + list2[i])
print("List 1:", list1)
print("List 2:", list2)
print("Sum of elements:", result)
Output:
List 1: [1, 2, 3, 4]
List 2: [5, 6, 7, 8]
Sum of elements: [6, 8, 10, 12]
2. Program to calculate Mean, Median and Mode using NumPy
Aim: To calculate mean, median and mode of a dataset.
import numpy as np
from scipy import stats
data = [2, 4, 6, 8, 10, 10]
mean = [Link](data)
median = [Link](data)
mode = [Link](data)
print("Data:", data)
print("Mean:", mean)
1
print("Median:", median)
print("Mode:", [Link][0])
Output:
Data: [2, 4, 6, 8, 10, 10]
Mean: 6.6667
Median: 7.0
Mode: 10
3. Program to display a Line Chart
Aim: To display a line chart for given points.
import [Link] as plt
x = [2, 3, 4, 5, 6, 7, 8, 9]
y = [5, 6, 7, 8, 9, 10, 11, 12]
[Link](x, y)
[Link]("X-axis")
[Link]("Y-axis")
[Link]("Line Chart")
[Link]()
Output: A line graph showing increasing values.
4. Program to display a Scatter Chart
Aim: To display a scatter chart for given points.
import [Link] as plt
x = [2, 9, 8, 5, 6]
y = [5, 10, 3, 7, 18]
[Link](x, y)
[Link]("X-axis")
[Link]("Y-axis")
[Link]("Scatter Chart")
[Link]()
Output: A scatter plot of the given points.
2
5. Program to read a CSV file and display first 10 rows
Aim: To read a CSV file and display its first 10 rows.
import pandas as pd
df = pd.read_csv("[Link]")
print([Link](10))
Example Output: Displays first 10 rows of the CSV file.
6. Program to read a CSV file and display its information
Aim: To display structure and information of a CSV file.
import pandas as pd
df = pd.read_csv("[Link]")
print([Link]())
Output: Shows column names, data types and memory usage.
7. Program to read and display an Image
Aim: To read and display an image using Python.
from PIL import Image
import [Link] as plt
img = [Link]("[Link]")
[Link](img)
[Link]("off")
[Link]()
Output: Displays the image on the screen.
8. Program to read an Image and identify its shape
Aim: To find the shape of an image.
import cv2
3
img = [Link]("[Link]")
print("Image shape:", [Link])
Example Output:
Image shape: (480, 640, 3)
Note: Replace [Link] and [Link] with actual file names available on your system.