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

Updated Practical Work Python Class 9 - 10

Uploaded by

Anya Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Updated Practical Work Python Class 9 - 10

Uploaded by

Anya Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1) Write a program to add the elements of the two lists.

list_1 = [1, 'a']


list_2 = [3, 4, 5]
list_joined = list_1 + list_2
print(list_joined)

2) Write a program to calculate mean, median and mode using Numpy


import statistics
statistics.mean([4, 8, 6, 5, 3, 2, 8, 9, 2, 5]) – 5.2
statistics.median([3, 5, 1, 4, 2]) – 3
statistics.median([3, 5, 1, 4, 2, 6]) – 3.5
statistics.mode([4, 1, 2, 2, 3, 5]) - 2
statistics.mode([4, 1, 2, 2, 3, 5, 4]) - 4
st.mode(["few", "few", "many", "some", "many"]) - 'few'

3) Write a program to display line chart from (2,5) to (9,10).


import matplotlib.pyplot as plt
import numpy as np
x = np.array([2, 5])
y = np.array([9,10])
plt.plot(x, y) plt.show()

4) WAP to display a scatter chart for the following points(2,5),(9,10),(8,3),(5,7),(6,18).


import matplotlib.pyplot as plt
price = [2, 1, 4, 3, 5, 4]
sales_per_day = [34, 62, 49, 22, 13, 19]
plt.scatter(price, sales_per_day)
plt.show()

5) Read csv file saved in your system and display 10 rows.


# Import pandas
import pandas as pd
# reading csv file
df = pd.read_csv(r"people.csv")
print(df.head(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())

7) Write a program to read an image and display using Python


import matplotlib.image as mpimg
import matplotlib.pyplot as plt
img = mpimg.imread(r'g4g.png')
plt.imshow(img)

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.

2) To print the following patterns using multiple print commands-

3) To find square of number 7.

4) To find the sum of two numbers 15 and 20.

5) To convert length given in kilometers into meters. (Hint : 1km = 1000m)

6) To print the table of 5 up to five terms.

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)

10) To input marks of 3 subjects and calculate their average.

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)

13) Create a list num=[23,12,5,9,65,44]


a) Print the length of the list – len(num)
b) Print the elements from second to fourth position using positive indexing – num[1:4]
c) Print the elements from position third to fifth using negative indexing – num[-4:-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)

15) Create a list l1=[10,20,30,40].


a) Add the elements [14,15,12] using extend function. – l1.extend([14,15,12]), print(l1)
b) Now sort the final list in ascending order and print it. – l1.sort(), print(l1)
16) To input age from user and check if a person can vote or not.

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

19) To print first 10 natural numbers

20) To print first 10 even numbers

21) To print odd numbers from 1 to n

22) To print sum of first 10 natural numbers

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.5 WAP in Python to demonstrate mode() function through a given data-set :


[1, 2, 3, 4, 4, 4, 4, 5, 6, 7, 7, 7, 8] using Python statistical functions.
A.5 import statistics
data1 = [1, 2, 3, 4, 4, 4, 4, 5, 6, 7, 7, 7, 8]
print("Mode of data-set is : ", statistics.mode(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))

You might also like