+ 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
BasharGh123 - avatar
13 odpowiedzi
+ 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
visph - avatar
+ 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
IbrahimCPS - avatar
+ 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
Dramani Yinsongte Kizito - avatar
+ 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
Kareem Aladawy
Kareem Aladawy - avatar
+ 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
Kareem Aladawy
Kareem Aladawy - avatar
+ 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
Abhishek Verma - avatar
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
Bouzidi Ikram - avatar
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
Fares Emad
Fares Emad - avatar
0
vac = { 'never': 5, 'once': 8, 'twice': 4, '3 times': 3 } num_vac =[] num_vac.append(vac['once']) num_vac.append(vac['twice']*2) num_vac.append(vac['3 times']*3) sum_people = vac['once'] + vac['twice'] + vac['3 times'] + vac['never'] mean_vac = sum(num_vac)/sum_people print(mean_vac)
19th Oct 2021, 7:43 AM
Ventsislav Georgiev
Ventsislav Georgiev - avatar
0
sum=0; for i in range(len(vac_nums)): sum=sum+vac_nums[i] print(sum/len(vac_nums))
23rd Feb 2022, 6:32 PM
Hari Prasaanth
Hari Prasaanth - avatar
0
Here is my solution! vac_nums = [0,0,0,0,0, 1,1,1,1,1,1,1,1, 2,2,2,2, 3,3,3 ] def variance(vac_nums): mean = sum(vac_nums)/len(vac_nums) deviations = [(x - mean) ** 2 for x in vac_nums] variance = sum(deviations) /len(vac_nums) return(variance) print(variance(vac_nums))
1st Jan 2023, 9:47 PM
Zahra Nemati
Zahra Nemati - avatar
0
my solution is 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(mean:=sum(vac_nums)/len(vac_nums))
11th Jan 2023, 11:27 AM
Nihal Bhardwaj
Nihal Bhardwaj - avatar
- 3
This is my solution! import numpy as np never = np.array([0 for x in range(5)]) once = np.array([1 for x in range(8)]) twice = np.array([2 for x in range(4)]) three = np.array([3 for x in range(3)]) total = np.concatenate((never, once, twice, three), axis=None) print(np.mean(total))
11th Jun 2021, 7:39 AM
Hải Lê Trung
Hải Lê Trung - avatar