-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
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

0

Try this.

nth = 2

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

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

print(total)
norie
  • 9,609
  • 2
  • 11
  • 18