Android & iPhone apps are coming soon. Log in for a plan and reminders made for you →

Coding basics · 10 of 20

Star triangle

Return n rows of a triangle as a list of strings: row 1 is "*", row 2 is "**", up to n stars.

What you need

A loop inside a loop: the inner one runs fully for every step of the outer one. Strings can be built with +=.

for row in range(1, 3):
    line = ""
    for _ in range(row):
        line += "#"
    print(line)   # "#", then "##"

Examples

Input n = 3

Output ["*", "**", "***"]

Your code · Python

Stuck?