Ask Question

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.

+4
Answers (1)
  1. 30 June, 17:26
    0
    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers