Updated Practical Work Python Class 9 - 10
Updated Practical Work Python Class 9 - 10
6) Read csv file saved in your system and display its information
# Import pandas
import pandas as pd
# reading csv file
df = pd.read_csv(r"people.csv")
print(df.tail())
8) Write a program to read an image and identify its shape using Python.
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
img = mpimg.imread('g4g.png')
plt.imshow(img)
img.shape
Programs for class IX
1) To print personal information like Name, Father’s Name, Class, School Name.
7) To calculate Simple Interest if the principle_amount = 2000, rate_of_interest = 4.5 and time = 10
8) To input length(l) and breadth(b) from user and calculate Area and Perimeter of a rectangle.
(Hint : Area = l x b and Perimeter = 2*(l+b)
9) To input base(b) and height(h) from user and calculate Area of a triangle. (Hint : Area= ½*b*h)
11) To input length, breadth and height of a cuboid from user and calculate Surface Area and
Volume. (Hint : Total Surface area = 2 (length × breadth + breadth × height + length × height)
and Volume of the cuboid = (length × breadth × height))
12) Create a list named ‘squiz’ in Python of children selected for science quiz with following
names - Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik. Perform the following tasks
on the list in sequence :
a) Print the whole list
b) Delete the name “Vikram” from the list – squiz.remove(‘Vikram’)
c) Add the name “Jay” at the end – squiz.append(“Jay”)
d) Remove the item which is at the second position. – squiz.pop(1)
14) Create a list of first 10 even numbers, add 1 to each list item and print the final list.
Ans. even=[]
new=[]
for i in range(1,11):
if i%2==0:
even.append(i)
new.append(i+1)
print("Original List of Even Numbers:", even)
print("Modified List (Adding 1 to Each Item):", new)
17) To input percentage from user and print the grade of a student
18) To input a number and check if the number is positive, negative or zero and display
an appropriate message
23) To print the sum of all numbers stored in a list named list1.
Ans. total = 0
list1 = [11, 5, 17, 18, 23]
for ele in range(0, len(list1)):
total = total + list1[ele]
print("Sum of all elements in given list: ", total)
Q.1 WAP in Python using the Matplotlib library to generate two scatter plots. The first set of
data points (x=[1, 2, 3, 4], y=[4, 1, 3, 6]), while the second set (x=[5, 6, 7, 8], y=[1, 3, 5, 2]).
A.1 import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [4, 1, 3, 6]
plt.scatter(x, y)
plt.show()
x = [1, 2, 3, 4]
y = [4, 1, 3, 6]
plt.scatter(x, y)
plt.show()
Q.2 WAP in Python to draw a horizontal line and a vertical line both in one graph (like plus symbol)
with the help of matplotlib. Here we will use two list as data with two dimensions (x and y).
Show Legends also.
A.2 import matplotlib.pyplot as plt
x = [10,20,30,40,50]
y = [30,30,30,30,30]
plt.plot(x, y, label = "line 1")
plt.plot(y, x, label = "line 2")
plt.legend()
plt.show()
Q.3 WAP in Python to create a vertical bar chart Setting x_label as Pen sold and y_label as Price
and title as Vertical Bar. x=['one', 'two', 'three', 'four', 'five'] and y=[5, 24, 35, 67, 12].
A.3 import matplotlib.pyplot as plt
x = ['one', 'two', 'three', 'four', 'five']
y = [5, 24, 35, 67, 12]
plt.bar(x, y, color='skyblue')
plt.xlabel('Pen Sold')
plt.ylabel('Price')
plt.title('Vertical Bar')
plt.show()
Q.4 WAP in Python to calculate mean/average of a given list of numbers [1, 3, 4, 5, 7, 9, 2] using
Python statistical functions.
A.4 import statistics
data1 = [1, 3, 4, 5, 7, 9, 2]
print("Mean of data-set is : ", statistics.mean(data1))
Q.6 WAP in Python to demonstrate median() function through a given data-set : [1, 3, 3, 4, 5, 7]
using Python statistical functions.
A.6 import statistics
data1 = [1, 3, 3, 4, 5, 7]
print("Median of data-set is : ", statistics.median(data1))