Sum up all the integers in range()

Viewed 71105

I need to write a program that sums up all the integers which can be divided by 3 in the range of 100 to 2000. I'm not even sure where to start, so far I've got this tiny piece of code written which isn't correct.

for x in range(100, 2001, 3):
      print(x+x)

Any help is much appreciated!

6 Answers

Let's do it in Recursive way .

Utilizing a range_sum function

def range_sum(array):
if array[0]==array[1]:
    return array[0]
else:
    return range_sum([array[0],array[1]-1])+array[1]
range=[1,4]
print(range_sum(range))

10

Related