0
Can someone please help me with the following.
I want to add all the deviations and devide the answer by the number of deviation to calculate the mean deviation. But I don't know how to do it. https://code.sololearn.com/cGewJL9712dj/?ref=app
5 Answers
+ 3
Use your a variable in your sdi function within the loop add each value to the variable a.
a += deviations
Then after the loop has completed, either print or return the value of a divided by the length of the list numbers to get the mean of the deviations.
mean = a/len(x)
return mean or print(mean)
def sdi(x):
a = 0
for xi in x:
deviations = abs(xi - median)
a += deviations
print (deviations)
mean = a/len(x) # print or return mean
+ 3
print(f"{mean:.2f}")
+ 2
Please tag a relevant language (Python) đ
0
Thank you very much ChaoticDawg
just one more question "how can I limit the mean deviation to only two decimal places.
0
#ipang : ok I will do it next time.