-1

Given that a list

[10,20,30,40,50,60]

If I want to sum up every second number. For instance 20+40+60=120. So what should I write in python? Is it while loop or for loop?

Barmar
  • 669,327
  • 51
  • 454
  • 560

1 Answers1

0

Try this.

nth = 2

values = [10,20,30,40,50,60]

total = sum(values[1::nth])

print(total)
norie
  • 9,146
  • 2
  • 10
  • 17