Number Pattern 1

Print number pattern: 1, 12, 123, ...

IntermediatePhase 2 - Level 4: Pattern PrintingExample 4 of 13
number-pattern-1.py
1# Take n
2n = int(input("Enter number of rows: "))
3
4# Print pattern
5for i in range(1, n + 1):
6 for j in range(1, i + 1):
7 print(j, end="")
8 print()

Output

Enter number of rows: 4
1
12
123
1234

What's going on

Print numbers from 1 to i in each row.

Key Concepts:

Outer loop: rows
Inner loop: print j from 1 to i
Sequential numbers