Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteUse a nested loop to print 1, 12, 123, and later rows: the outer loop selects the row, and the inner loop prints each number from 1 through that row’s number. The examples below show five approaches, then eight related patterns.
The basic nested-loop solution
rows = 5
for row in range(1, rows + 1):
for value in range(1, row + 1):
print(value, end="")
print()
Output:
1
12
123
1234
12345
rows sets the number of lines. The outer loop assigns each line a number from 1 through rows; the inner loop prints values from 1 through the current row number. Python’s range(start, stop) includes the start but excludes the stop, so row + 1 makes the current row number part of the sequence. The Python 3.14.8 tutorial explains that the endpoint is not included in a generated range.
As an Amazon Associate I earn from qualifying purchases.
print(value, end="") keeps the values together on one line instead of adding a newline after each value. Once the inner loop finishes, the standalone print() moves output to the next line. The same line-ending behavior is used in the direct pattern example from Python Guides.
Five ways to create the pattern
These approaches produce the same ascending triangle except for the fifth, which deliberately makes a repeated-digit pattern. The nested for loop is the clearest starting point for learning how the row and value loops work.
#1 Best Overall
| Method | Code | Best suited to |
|---|---|---|
1. Nested for loops |
|
Seeing both loop boundaries and how each row is built. |
2. Nested while loops |
|
Practicing explicit counter setup and increments. Reset value to 1 for each row. |
| 3. Build a row string |
|
Separating construction of a line from printing it. |
| 4. Use a comprehension |
|
A compact variation. The inner comprehension creates the values for one row; the outer loop prints each row. |
| 5. Repeat the row number |
|
A related repeated-digit pattern, not the ascending sequence. |
Methods 3 and 4 express the same row-by-row logic while constructing a string before printing. Method 5 changes the rule: it repeats each row number instead of counting from 1 within each row. A beginner-oriented nested-loop triangle also appears in Waterside Code Club’s Python From Zero To One.
Eight related pattern variations
Each variation changes a loop boundary, the value printed, or the spacing. Here, rows = 5 unless the example uses another setting.
Rank #2
1. Repeated digit on each row
Output:
1
22
333
4444
55555
for row in range(1, rows + 1):
print(str(row) * row)
Multiplying the row’s string by its number repeats that digit; this is the repeated-digit pattern shown as method 5.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →2. Descending row lengths
Output:
12345
1234
123
12
1
for row in range(rows, 0, -1):
for value in range(1, row + 1):
print(value, end="")
print()
The outer loop counts downward, so each new row is shorter.
3. Descending values within each row
Output:
1
21
321
4321
54321
for row in range(1, rows + 1):
for value in range(row, 0, -1):
print(value, end="")
print()
The inner loop starts at the row number and counts down to 1.
4. Add spaces between ascending values
Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
for row in range(1, rows + 1):
print(" ".join(str(value) for value in range(1, row + 1)))
Joining the values with a space changes the separator, not the numbers in each row.
5. Print an asterisk triangle
Output:
*
**
***
****
*****
for row in range(1, rows + 1):
print("*" * row)
This replaces the numbers with a repeated asterisk.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problems6. Continue consecutive integers across rows
Output:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
rows = 5
value = 1
for row in range(1, rows + 1):
for _ in range(row):
print(value, end=" " if _ < row - 1 else "")
value += 1
print()
Unlike the original pattern, this keeps one counter across rows rather than restarting each row at 1.
Best Value
7. Center a number pyramid
Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
rows = 5
for row in range(1, rows + 1):
numbers = " ".join(str(value) for value in range(1, row + 1))
print(" " * (rows - row) + numbers)
Leading spaces move shorter rows to the right. This is a simple text alignment; it is not a geometrically centered pyramid when the number of digits or spacing changes.
8. Ascending and then descending values
Output:
1
121
12321
1234321
123454321
for row in range(1, rows + 1):
up = range(1, row + 1)
down = range(row - 1, 0, -1)
print("".join(str(value) for value in up), end="")
print("".join(str(value) for value in down))
The descending part starts at row - 1 so the peak value is not printed twice.
Quick Recap
Common mistakes and fixes
- Only one value appears per line: the inner
print()is ending each line. Useend=""(or a chosen separator) while printing each value, then callprint()after the inner loop. - The last value is missing:
range()excludes its stop value. For an inclusive endpoint ofrow, userange(1, row + 1). - The while-loop never ends: increment
valueinside the inner loop androwafter the row is printed. Resetvalueat the start of each row. - The fifth method does not print
123:str(row) * rowintentionally repeats one digit, producing333on row 3. Use the nested loop or row-string method for123.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Free tools Windows power users keep installed
One-click scans. No signup required.




