Python Program to Print a Right Triangle Star Pattern
mediumNested loopsPython
Pattern programs are a practical-exam favourite. Python's string repetition makes this one very short.
The question
Read the number of rows n and print a right-angled triangle of stars: 1 star on the first row, 2 on the second, and so on. No spaces between the stars.
The code
Input
5
Output
* ** *** **** *****
How it works
- 1The loop runs once per row, i going from 1 to n.
- 2"*" * i repeats the star i times — 1 star on row 1, 2 on row 2, and so on.
- 3Each print() starts a new row.
Common mistakes
- range(n) starts at 0, so the first row prints nothing.
- Adding spaces between stars when the question asks for none.
Now solve a similar question yourself
A new Python question every time, checked instantly.
