Range() in a for Loop 2/2
Note
In many of our tasks, we'll frequently employ a
counter
variable to facilitate basic arithmetic operations.For instance, if we wish to sum 2 and 3, we'll initialize the
counter
withcounter = 0
and then add 2 and 3 to it:counter = 0 + 2 + 3 = 5
=>counter = 5
.The utilization of such variables is essential for managing straightforward mathematical operations effectively.
Take a look at the following code:
How does the code work?
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/1_3_mdk.gif)
Завдання
We've previously seen an example of summing elements from 50 to 100 using an increasing list. Now, let's tackle this task with a decreasing list:
- Establish a
for
loop, utilizingi
as an element of the range and setting step = -1. - Execute the summation by adding the elements within the range.
- Print the value of the
counter
.
Все було зрозуміло?
Зміст курсу
Python Loops Tutorial
Python Loops Tutorial
Range() in a for Loop 2/2
Note
In many of our tasks, we'll frequently employ a
counter
variable to facilitate basic arithmetic operations.For instance, if we wish to sum 2 and 3, we'll initialize the
counter
withcounter = 0
and then add 2 and 3 to it:counter = 0 + 2 + 3 = 5
=>counter = 5
.The utilization of such variables is essential for managing straightforward mathematical operations effectively.
Take a look at the following code:
How does the code work?
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/c5b4ea8f-8a30-439f-9625-ddf2effbd9ac/1_3_mdk.gif)
Завдання
We've previously seen an example of summing elements from 50 to 100 using an increasing list. Now, let's tackle this task with a decreasing list:
- Establish a
for
loop, utilizingi
as an element of the range and setting step = -1. - Execute the summation by adding the elements within the range.
- Print the value of the
counter
.
Все було зрозуміло?