For Loops 2

data = [6, 7, 8]

for i in range(len(data)):

data[i] = 0

sumVal = 0

______________________________________________________________________________________________________________________

for i in range(10):

sumVal = sumVal + i

print(sumVal / 10)


4.5

In the above example, our data list is the output of range(10), which is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The variable sumVal is first declared and has each value of i added to it. As there are 10 values added to the sumVal, we complete the average calculation by dividing sumVal by 10. Our result 4.5 is the average from the data: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.