+ 1

# Number of Vaccinations Activity

In the new course "Python in Data Science", there is an activity called "Number of Vaccinations" which is very easy but I can't get the answer right. Here is the link for the activity, and any help would be highly appreciated, Thank you. The link: https://www.sololearn.com/learning/1161/4777/12269/1

19th Mar 2021, 11:45 AM
BasharGh123
+ 5
you must carefully read the hint provided: Hint: Think about the data this way: it contains 20 values, each representing the number of vaccinations the corresponding person had. then, you could visualize better the data set by writtng it: ds = [ 3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 ] hope this help! :)
19th Mar 2021, 12:25 PM
visph
+ 5
vac_nums = [0,0,0,0,0, 1,1,1,1,1,1,1,1, 2,2,2,2, 3,3,3 ] #your code goes here print((0*5+8*1+4*2+3*3)/20)
25th Jan 2022, 9:24 PM
IbrahimCPS
+ 3
Note the variance is the squared difference between the mean and the values. So all you need to do is to subtract the mean from the value and square it. def variance(X): mean = sum(X)/len(X) tot = 0.0 for x in X: tot = tot + (x - mean)**2 return tot/len(X) sample=[0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3] print(variance(sample)) This code works perfectly 👌.
27th Aug 2021, 11:53 AM
Dramani Yinsongte Kizito
+ 2
Here's my solution using a dictionary to allow me to add the values easily, please consider reading the code carefully https://code.sololearn.com/c8y85eVu6Z8i/?ref=app
4th Apr 2021, 10:09 AM
+ 2
LIN, ZHI-JIA yeah I noticed it but it just didn't accept this way for a reason I don't know yet
10th Apr 2021, 6:35 PM
+ 1
This is my solution ! Number of Vaccinations: vac_nums = [0,0,0,0,0, 1,1,1,1,1,1,1,1, 2,2,2,2, 3,3,3 ] #your code goes here mean = sum(vac_nums)/len(vac_nums) diff = 0.0 for i in vac_nums: diff = diff + (mean - i)**2 variance = diff / len(vac_nums) print(variance)
1st Aug 2022, 5:48 AM
Abhishek Verma
0
this is your data [0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3] the result is print ((0*5+1*8+2*4+3*3)/20)
2nd Aug 2021, 7:25 PM
Bouzidi Ikram
0
nums={0:5,1:8,2:4,3:3} arr=[] for key,val in nums.items(): for i in range(key): arr.append(val) #arr will be [8,4,4,3,3,3] #mean print(sum(arr)/20)
11th Oct 2021, 7:48 PM