221,635 views
24 votes
24 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 Vernell
by
2.9k points

1 Answer

10 votes
10 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 PStan
by
3.1k points