Pyramid Printer ๐บ
Final boss. ๐
*
***
*****
*******
That's pyramid(4). Look very closely at row 3 of 4: it has
2 spaces in front and 5 stars. Row 4 has 1 space... no wait,
0 spaces and 7 stars.
See the pattern? For a pyramid of n rows, on row i:
- spaces in front =
n - i - stars =
i * 2 - 1
Check it: row 1 of 4 โ 3 spaces, 1 star. Row 4 of 4 โ 0 spaces, 7 stars. It works! ๐ฏ
Build the line with repetition and glue it together:
line = " " * 3 + "*" * 1
print(line)
Your mission
Write a function called pyramid(n) that prints an n-row
star pyramid, centred with spaces.
This one prints instead of returning โ I'll call pyramid(4) and
pyramid(3) and count your stars and spaces. Make it work for any
n, not just one. ๐๏ธ
Your code
Press โถ Run to see what your code does!