- 1

Phyton, data science

Does someone know how exactly the code should look for the ex below? I also add what I have done (the code was empty) 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 #your code goes here arr=[5,8,8,3,3,4,4,3,8,5,3,3,3,4,4,8,5,8,5,3]; sum= 0; k=0; for i in range(len(arr)): if arr[i] !=8: sum+=arr[i]; k=k+1; print(sum/k);

27th Mar 2021, 8:50 PM
Zotta
Zotta - avatar
9 Antworten
+ 1
Jayakrishna🇮🇳 i don't know, mean the test case is closed so ca not see how the answer should look
27th Mar 2021, 9:08 PM
Zotta
Zotta - avatar
+ 1
Ok, well nvm if you got it figured out lol
27th Mar 2021, 9:20 PM
ChaoticDawg
ChaoticDawg - avatar
0
vac_nums = [0,0,0,0,0, 1,1,1,1,1,1,1,1, 2,2,2,2, 3,3,3 ] print((8+8+9)/20) It works...
7th Jul 2022, 2:49 AM
Monika Raut
Monika Raut - avatar
0
vac_nums = [0,0,0,0,0, 1,1,1,1,1,1,1,1, 2,2,2,2, 3,3,3 ] #never =0 so 5*0 once =8 so 1*8 twice =2 so 2*4 3 times =3 so 3*3 print ((8+8+9)/20)
22nd Nov 2022, 4:01 PM
Maisam Nisar
Maisam Nisar - avatar
- 1
Is the answer 1.6? edit: Zotta What i guessing for mean is 8*1 + 4*2 + 3*3 = 25 No.of people vaccinated is 20-5=15 25/15=1.666 am not sure, so if wrong ,i want delete my amswer. some other can answer....
27th Mar 2021, 9:06 PM
Jayakrishna 🇮🇳
- 1
Try like this; Never = 0 so 5 zeros Once = 1 so 8 ones Twice = 2 so 4 twos 3 times = 3 so 3 threes So, ((5 * 0) + (8 * 1) + (2 * 4) + (3 * 3)) / 20 Hopefully that makes sense.
27th Mar 2021, 9:13 PM
ChaoticDawg
ChaoticDawg - avatar
- 1
Jayakrishna🇮🇳 ChaoticDawg yeah, It seems I didn't understand correctly the exercise. I had to use only a print statement and the calculus that you used, thanks for helping
27th Mar 2021, 9:18 PM
Zotta
Zotta - avatar
- 1
You changed it lol. So, I'm guessing that a 5 in the list means never or 0, an 8 in the list means once or 1, etc. So if this is the cases you need to loop through the list and compare each value and add the appropriate correlating value to the total and then divide by the length of the list.
27th Mar 2021, 9:19 PM
ChaoticDawg
ChaoticDawg - avatar
- 1
Glad if that helped.. you're welcome..
27th Mar 2021, 9:27 PM
Jayakrishna 🇮🇳