11.6k views
0 votes
Add (total) all the number in the list (below) using a for loop, but skip over the number at index 3.

numbers = [10,20,30,40,50,60,100]

User RusHughes
by
5.8k points

1 Answer

3 votes

Answer:

The program in Python is as follows:

numbers = [10,20,30,40,50,60,100]

total = 0

for i in range(len(numbers)):

if i != 3:

total+=numbers[i]

print(total)

Step-by-step explanation:

This initializes the list

numbers = [10,20,30,40,50,60,100]

Set total to 0

total = 0

This iterates through numbers

for i in range(len(numbers)):

This ensures that the index 3, are not added

if i != 3:

total+=numbers[i]

Print the calculated sum

print(total)

User RSabet
by
6.2k points