1.
Q1: The following code is intended to store the sum of all the values in the integer list
arr in the variable total. Which of the following code segments can be used to replace # missing code/ so that the code works as intended?
total = 0
# missing code
print(total)
# I.
for pos in range(len(arr)):
total += arr[pos]
# ----
# II.
for pos in range(len(arr), 0, -1):
total += arr[pos]
# ----
# III.
pos = 0
while pos < len(arr):
total += arr[pos]
pos += 1
- I only
- II only
- III only
- I and III only
- II and III only
