Back to Practice
#0213
Centered Star Pyramid
MediumPython25 min20 XP
Problem
Return an n-row centered pyramid as a list of strings where row i has leading spaces and 2*i-1 stars.
Why This Matters
Centered patterns test whether you can derive row formulas instead of guessing output manually.
Function Signature
def centered_pyramid(n):
Examples
Example 1
Inputn = 3
Output[" *", " ***", "*****"]
Leading spaces shrink from 2 to 0 while stars grow from 1 to 5.
Constraints
- Return the exact requested value.
- Handle small edge cases cleanly.
- Prefer readable Python over clever shortcuts.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputn = 3
Expected[" *", " ***", "*****"]
Leading spaces shrink from 2 to 0 while stars grow from 1 to 5.
Hidden Test Categories
small inputlarger inputedge shape