Range() in a for Loop 2/2Range() in a for Loop 2/2

Note

We will often use the counter variable in our tasks to perform simple math operations.

For example, if we want to add 2 and 3, we need to create the counter, set counter = 0, and then add 2 and 3 to the counter: counter = 0 + 2 + 3 = 5 => counter = 5.

We should use this kind of variable, or we won't be able to handle the implementation of simple math operations.

Look at the code below:

How does the code work?

Task

We learned an example of adding elements from 50 to 100. We did that with the increasing list. Now we need to remake the task for the decreasing list.

  1. Set a for loop, using i as an element of the range and setting step = -1.
  2. Implement the sum by adding elements inside the range.
  3. Print the counter.

Everything was clear?

Section 1. Chapter 3
toggle bottom row