Start free

Beginner · For loops · 80 of 264

Staircase of stars

Read n and print a staircase: row 1 has one star, row 2 has two, up to n stars.

Input: a positive whole number n. Output: n rows of stars.

Examples

Input
3
Output
*
**
***
Input
1
Output
*

One more test checks other inputs when you press Check.

Stuck? The idea behind for loops

A for loop repeats its indented lines once for each item: each letter of a string, each item of a list, or each number of a range.

range(5) is 0 to 4; range(1, 6) is 1 to 5; range(10, 0, -1) counts down from 10 to 1.

total = 0
for i in range(1, 6):
    total += i
print(total)  # 15

Watch for: range stops before its end: range(1, n) leaves out n. A print inside the loop prints every time; outside it (not indented), once at the end.

All the for loops exercises
Your code
Opening the code editor…
Python 3.14 in your browser
Output
Run shows what your program prints. Check tests it on every example and the hidden tests.

More for loops exercises