70.5k views
0 votes
Below, we’ve provided a for loop that sums all the elements of list1. Write code that accomplishes the same task, but instead uses a while loop. Assign the accumulator variable to the name accum.

User ScottWest
by
4.8k points

1 Answer

7 votes

Answer:

Step-by-step explanation:

The code that would best accomplish this task using a while loop would be the following:

list1 = [8, 3, 4, 5, 6, 7, 9]

accum = 0

n = 0

while n < 7:

accum += list1[n]

n += 1

This code will continue throughout the list1 array and add every value to the accum variable.

User MrKew
by
5.1k points