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

b) Find mean, median, mode for the given set of numbers in alist.

Source code :
#To calculate mnean
def mean(l):
add=0
for x in range(0,a):
add=add+|[x]
mean=add/a
print("'mean of the given list is ",mean)
#to calculate median
def median(l):
I.sort()
print("sortedorder of list :")
if(a%2==0):
nl=//2
n2=nl-1
md-(U[nl+l[n2])/2
print("median is".md)
else:
PYTHON PROGRAMMING
APPLICATIONS LAB

n=al/2
print("median is",I[n])
#calculate mode
det mode(l):
for x in I:

|l.append(l.count())
m=max(1)
print("mode is",I[l1.index(m))
#read size and elements into list

I1=0
i=0
m=int(input("Enter the size of the list:")
while(i<m):
L.append(int(input("enter the element:")
i=i+l
print("the list contains:")
a=len(l)
mean(l)
median(|)
mode(l)

Output:
Enter the size of the list:4

enter the element:1

enter the element:2

enter the element:3

enter the element:4

the list contains: |1, 2, 3, 4]


mean of the given list is 2.5
sorted order of list : |1, 2, 3, 4]
median is 2.5

mode is 1

ENGINEERING &TECHNOLOGY Page 21

You might also like