+ 5

2.2 Practice - Vaccinations Report - Python for Data Science

We have a report on the number of flu vaccinations in a class of 20 people. It has the following numbers: never: 5 once: 8 twice: 4 3 times: 3 What is the mean number of times those people have been vaccinated? Output the result using the print() statement Hint: Think about the data this way: it contains 20 values, each representing the number of vaccinations the corresponding person had. === This is introductory but I can't figure out the solution. Could you please help me? Neither line seems to work for the hidden case: print( (5+8+4+3) / 4 ) print( (5+8+4+3) / 20 )

20th Apr 2021, 6:15 PM
boneSpider
boneSpider - avatar
7 Answers
+ 3
Thanks Jerry Hobby, good point. I tried this but it doesn't work either: print( (0*5) + (1*8) + (2*4) + (3*3) / 4 ) What am I missing to find the mean of the number of flu vaccinations for 20 people?
20th Apr 2021, 8:08 PM
boneSpider
boneSpider - avatar
+ 2
Yes you can try making a dict of values and append the values to the are and find the avg👌 Something like nums={0:5,1:8,2:4,3:3} # since 5 is once,8 is twice and so on.. arr=empty list for key,val in nums.items(): for i in range(key): append values to arr #arr will be equal to [8,4,4,3,3,3] #mean print(sum(arr)/20)
27th Apr 2021, 4:27 PM
Aditya
Aditya - avatar
+ 2
[1] vac_nums = [0,0,0,0,0, 1,1,1,1,1,1,1,1, 2,2,2,2, 3,3,3] [2] [vac_nums.count(x) * x for x in set(vac_nums)] >>> [0, 8, 8, 9] [3] len(vac_nums) >>>> 20 [4] sum([vac_nums.count(x) * x for x in set(vac_nums)]) / len(vac_nums) >>>> 1.25
9th Jan 2022, 7:24 PM
Marcio
+ 2
Simply to find the mean, just do the following equation: print((8+8+9)/20) Since one time vaccination: 8 Since two times vaccination: 4 x 2 = 8 Since three times vaccination: 3 x 3 = 9 Add them all together and then divide by the total number of students which is 20. This should help.
29th Jul 2022, 7:48 PM
♥️ʀᴏxꜱɪᴇɪɪ♥️
♥️ʀᴏxꜱɪᴇɪɪ♥️ - avatar
+ 1
You aren’t adding up twenty numbers. Repeat the numbers the specified number of times.
20th Apr 2021, 7:29 PM
Jerry Hobby
Jerry Hobby - avatar
+ 1
Divide by 20?
20th Apr 2021, 8:57 PM
Jerry Hobby
Jerry Hobby - avatar
0
never=[0,0,0,0,0] once=[1,1,1,1,1,1,1,1] twice=[2,2,2,2] third=[3,3,3] total=never+once+twice+third sum(total)/20
17th Jan 2022, 1:46 AM
zeinab homayounmher