Loops in Python 3

Hello,

I’m in the python 3 course, and I am having some trouble really understanding loops. I am going through the exercises and keep finding myself having to get the program to display the solution. Any other places I can go to get some more help with loops?

1 Like

Google is your friend.

Or… ask a specific question and the community can help to explain. :slight_smile:

1 Like
print (1)
print (2)
print (3)
print (4)
print (5)
print (6)
print (7)

The above will print,

1
2
3
4
5
6
7

We’ve got repetition in that the code pattern of each line is the same, but for the argument, a single number. The numbers are in sequence.

With a loop we can bundle the repeated code into one block within a looping construct.

for i in range(1, 8):
    print (i)

which when we run it will output,

1
2
3
4
5
6
7

Notice how the loop gets rid of the repeated code pattern?

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.