Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python 2.7 multiple choice question This is a MULTIPLE ANSWER question, which me

ID: 3838103 • Letter: P

Question

Python 2.7 multiple choice question

This is a MULTIPLE ANSWER question, which means you are able to select one or more answers as being correct. Note that this does not necessarily mean that there are multiple correct answers. In any case, select all the answers you believe are correct. There is a Python list of integers called rainfall. Which of the following blocks of code would find the average of the integers contained in rainfall? sum = 0 for amount in rainfall; sum = amount average = sum/len (rainfall) for amount in rainfall; sum = 0 sum = sum + amount average = sum/len (rainfall) sum = 0 for amount in rainfall; sum = amount average = sum/len (rainfall) sum = 0 for amount in rainfall; sum = sum + amount average = sum/len (rainfall) for amount in rainfall; sum = 0 sum = sum + amount average = sum/len (rainfall) sum = 0 for amount in rainfall sum = sum + amount average = sum/len (rainfall)

Explanation / Answer

Average = Sum of all integer/number of integers.

(1) The first option doesn't compute average correctly, because in the for ;loop every iteration the integer is assigned to sum never added.

(2) It also doesn't compute average correctly, because in the for loop every iteration sum is set to 0, so not maintaing the sum of integers calculated so far.

(3) It also doesn't compute average correctly, because in the for loop the integer is assigned to sum never added.

(4) It computes average correctly. Though in every iteration it computes the average, when the loop ends it will contain the correct average.

(5) It also doesn't compute average correctly, since in the for loop every iteration sum is set to 0, so not maintaing the sum of integers calculated so far.

(6) It computes average correctly.