n = ? → print each i
🛗
Floor 1
1for i in range(1, n + 1):
2print(i)
1\n2\n3
Loop syntax highlight: for i in range(1, n + 1): then run print(i) inside the loop body.
range(1, n+1) is the list of numbers to visit.
This loop starts at 1 and prints every number until n. It is the most basic example of repeating one action many times.
Used for counting pages, floors, turns, attempts, IDs, and any task where you need to process every number in a fixed range.
Going up 5 floors? You hear five announcements. The loop variable i is the current floor; the body is “say the number”.
print(i) adds a new line in output.