Print a Right-Angled Star Pyramid

Medium ⏱ 12 min 57% acceptance ★★★★☆ 4.2
Write a function star_pyramid(n) that returns a list of n strings where row i (1-indexed) contains i asterisk characters ("*") with no separators, forming a left-aligned right-angled triangle.

Examples

Example 1
Input
star_pyramid(4)
Output
["*", "**", "***", "****"]
Explanation

Row i has i stars.

Constraints

  • n is a positive integer.

Topics

Loopsnested loopspattern printing

Companies

IBMOracle

Hints

Hint 1

Use nested loops: outer for the row, inner to build the star string, or use string multiplication `"*" * i`.

Hint 2

Append each row string to a results list.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.