Python Practice › Loop Programs › Program 59

Star triangle up and down

EasyLoop Programs · 59 of 90

Write a Python program to print stars growing from 1 to 5 and back to 1.

Advertisement
Output
* 
* * 
* * * 
* * * * 
* * * * * 
* * * * 
* * * 
* * 
* 

Approach

  1. Build the list of row sizes 1..5..1 and print each.

Solution

Python
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.

More loop programs

← All 90 Loop Programs

Leave a Comment