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

python code 6-10 class X

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

python code 6-10 class X

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

Date :

Practical 6: Program to create two matrices of 3x4 and add their elements.

Code Output
X = [[12,7,3,8],
[4,5,6,9],
[7,8,9,1]]
Y = [[5,8,1,5],
[6,7,3,2],
[4,5,9,1]]
result = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
for i in range(len(X)):
for j in range(len(X[0])):
result[i][j] = X[i][j] + Y[i][j]
for r in result:
print(r)
Date :
Practical 7: Program to calculate mean, median and mode using Numpy in Python.

Code Output
import statistics
import numpy
A=
[99,86,87,88,111,86,103,87,94,78,77,85,86]
x = numpy.mean(A)
y = numpy.median(A)
mode_result = statistics.mode(A)
print("mean:",x)
print("meadian:", y)
print("Mode:", mode_result)
Date :
Practical 8: Program to Read csv file saved in your system and display its
information/details.

Code Output
import csv
with open('Giants.csv', mode ='r')as file:
csvFile = csv.reader(file)
for lines in csvFile:
print(lines)
Date :
Practical 9: Program to create a dataframe named players and store their data in
the columns like team, no. of matches, runs and average. Assign player name as
row index and Display only those player details whose score is more than 1000.

Code Output
import pandas as pd
d = {'Team':
['India','Pakistan','England','Australia'],
'Matches': [25,23,19,17],
'Runs': [1120,1087,954,830],
'Average': [44.80,47.26,50.21,48.82]}
player = pd.DataFrame (d, index = ['Virat
Kohli','Babar Azam','Ben Strokes','Steve
Smith'])
high_scorers = player[player['Runs'] >
1000]
print(high_scorers)
Date :
Practical 10: Consider the following data of an Electronic store and plot the data
on the line chart.
Month Desktop Laptop Tablet
March 500 400 650
April 350 450 500
May 450 550 580
June 170 600 630
July 200 560 620
August 280 630 450

Code Output
import matplotlib.pyplot as plt

months = ['March', 'April', 'May', 'June', 'July',


'August']
desktop_sales = [500, 350, 450, 170, 200, 280]
laptop_sales = [400, 450, 550, 600, 560, 630]
tablet_sales = [650, 600, 580, 630, 620, 450]

plt.plot(months, desktop_sales, marker='o',


label='Desktop')
plt.plot(months, laptop_sales, marker='o',
label='Laptop')
plt.plot(months, tablet_sales, marker='o',
label='Tablet')

plt.title('Sales Data of Electronic Store')


plt.xlabel('Months')
plt.ylabel('Sales')
plt.legend()

plt.show()

You might also like