Computer Science, asked by Anonymous, 3 months ago

Make this more lite weight for low resource uses, comments are added for better understanding the language is python hope that u will help and don't use built in function for average or median

z=0

y=0

a=[1,2,3,4,5,6,7,8,9,10,11]

for k in a:

y=y+k #for finding the sum

z=z+1 #for finding the n

print('average=',y/z)

a=sorted(a) #built in function for sorting the items in a list

midterm=z/2 #z/2th term

if z%2==0: #% is used to find the remainder

#When n is even

print('median=',a[int(midterm)])

else:

#When in is odd

m=midterm-0.5

n=midterm+0.5

med=(a[int(m)]+a[int(n)])/2

print('median=',med)

Attachments:

Answers

Answered by Anonymous
2

The program is up to the mark, what's the problem over here, this type of programs can easily run even on low end machines. This isn't a resource intensive program but still...

z, y =0,0

a=[1,2,3,4,5,6,7,8,9,10,11]

sum=sum(a)

n=len(a)

print('average=',sum/n)

a.sort()

median=int(n/2)

if n%2==0:

mid=a[median]

else:

p=median-0.5

q=median+0.5

mid=(a[int(p)]+a[int(q)])/2

print("Median is", mid)

Similar questions