- 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);
9 Respuestas
+ 1
Jayakrishna🇮🇳 i don't know, mean the test case is closed so ca not see how the answer should look
+ 1
Ok, well nvm if you got it figured out lol
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...
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)
- 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....
- 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.
- 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
- 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.
- 1
Glad if that helped..
you're welcome..