Experiment 1 Code

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Code:

from statistics import mean,median,mode

def calculateStatistics(data):
meanValue = mean(data)
medianValue = median(data)
modeValue = mode(data)
return meanValue,medianValue,modeValue

data1 = [1, 2, 3, 4, 5, 4, 3, 2, 4, 5, 1, 2, 3, 4, 2, 5, 1, 3, 2, 1, 2, 1, 1, 1, 2]
data2 = [1, 2, 3, 4, 5, 4, 3, 2, 4, 5, 1, 2, 3, 4, 2, 5, 1, 3, 2, 1, 2, 1, 1, 1, 2000]
data3 = [1, 2, 3, 10, 20, 30, 100, 200, 300, 1000, 2000, 3000]

data1Mean,data1Median,data1Mode = calculateStatistics(data1)
data2Mean,data2Median,data2Mode = calculateStatistics(data2)
data3Mean,data3Median,data3Mode = calculateStatistics(data3)

print('For ', data1)


print('Mean: ',data1Mean)
print('Median: ',data1Median)
print('Mode: ',data1Mode)

print('For ', data2)


print('Mean: ',data2Mean)
print('Median: ',data2Median)
print('Mode: ',data2Mode)

print('For ', data3)


print('Mean: ',data3Mean)
print('Median: ',data3Median)
print('Mode: ',data3Mode)
Output:
For [1, 2, 3, 4, 5, 4, 3, 2, 4, 5, 1, 2, 3, 4, 2, 5, 1, 3, 2, 1, 2, 1, 1, 1, 2]
Mean: 2.56
Median: 2
Mode: 1
For [1, 2, 3, 4, 5, 4, 3, 2, 4, 5, 1, 2, 3, 4, 2, 5, 1, 3, 2, 1, 2, 1, 1, 1, 2000]
Mean: 82.48
Median: 2
Mode: 1
For [1, 2, 3, 10, 20, 30, 100, 200, 300, 1000, 2000, 3000]
Mean: 555.5
Median: 65.0
Mode: 1

You might also like