210k views
4 votes
Write code using the range function to add up to the series 20,30,40, ...90 and print the resulting sum each step along the way

Write code using the range function to add up to the series 20,30,40, ...90 and print-example-1

1 Answer

3 votes

Answer:

Code:

range_sum = 0

for x in range(20, 100, 10):

range_sum += x

print(range_sum)

Step-by-step explanation:

Declare variable (we'll use it to keep track of the sum):

range_sum = 0

Start a loop with the range function (x is the current number, 20, 100 are the numbers to start and stop by and 10 is the number to increase by):

for x in range(20, 100, 10):

Add the current number to the sum and print it:

range_sum += x

print(range_sum)

User Rum
by
4.2k points