Python Practice › Loop Programs › Program 59
Star triangle up and down
Write a Python program to print stars growing from 1 to 5 and back to 1.
Output
* * * * * * * * * * * * * * * * * * * * * * * * *
Approach
- Build the list of row sizes 1..5..1 and print each.
Solution
n = 5sizes = list(range(1, n + 1)) + list(range(n - 1, 0, -1))for s in sizes: print("* " * s)Output
* * * * * * * * * * * * * * * * * * * * * * * * *
Line by line
Line 2
The two ranges give 1, 2, 3, 4, 5, 4, 3, 2, 1.
Learn the concept
New to this topic? Read the lesson, then come back.