Number Pattern 1
Print an increasing digit triangle with Python nested loops. Students distinguish column values from row values and predict why numbering restarts on every row.
1# Take n2n = int(input("Enter number of rows: "))34# Print pattern5for 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
In this one
- Print a column counter
- Restart a row sequence
- Distinguish i from j
How it works
- 1
Visit row sizes one through n.
- 2
For each row, print j from one through i.
- 3
Finish the line after the inner loop.
Edge cases
Does numbering continue across rows?
Does numbering continue across rows?
No. j restarts at one.
What does n = 0 do?
What does n = 0 do?
It prints no rows.
What's going on
The outer i sets the width. The inner j starts at one for every new row and prints its own value.
For three rows, the lines are 1, 12, and 123. Printing j produces an increasing sequence across a row; printing i instead would repeat the row number. Multi-digit values after nine make the visual width less regular.
Does numbering continue across rows? No. j restarts at one.
What does n = 0 do? It prints no rows.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which variable is printed?
Pick an answer to check it.
Question 2
Does numbering continue across rows?
Pick an answer to check it.
Questions people ask
Does numbering continue across rows?
No. j restarts at one.
What does n = 0 do?
It prints no rows.
Which variable is printed?
j.
๐Related Content
- ๐
Phase 2 - Learn Concepts
Review Phase 2 concepts and explanations
- ๐
Phase 2 - Quiz
Test your Phase 2 understanding with quiz questions
- ๐ป
Phase 2 - All Practice Problems
Explore all practice problems for Phase 2
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum