concept range(3 in category python

appears as: rge(3
Get Programming: Learn to code with Python

This is an excerpt from Manning's book Get Programming: Learn to code with Python.

circles  = Stack()
for i in range(3):
    one_circle = Circle()
    one_circle.change_radius(3)
    circles.add_one(one_circle)
rectangles  = Stack()
one_rectangle = Rectangle(1, 1)
rectangles.add_many(one_rectangle, 5)

You can generalize the behavior in listing 16.2 by using a different variable, say n_times, instead of 3, to give a sequence of numbers denoted by range(n_times). Then the loop will repeat n_times times. Every time the loop variable takes on a different value, the statements inside the code block are executed.

Figure 18.3. (A) shows the for loop code that prints the value of the loop variable with each iteration of the loop. (B) shows the while loop code and how the variables in change values when the for loop is converted into a while loop. You have to create your own variable and increment it yourself inside the body of the while loop. Additionally, you have to write a conditional as a function of your variable that will cause the body of the while loop to repeat three times.