π
Star tree
Grow a triangle of stars row by row using a loop.
SproutΒ· ages 8β1015 minfor loopsrangestrings
star_tree.py
β¦First load pulls ~10Β MB of Python. Only happens once β the browser caches it after.
What should the output look like?
Your tree should have several rows of stars, wider at the bottom than the top.
π
How this works
Every row of the tree has one more star than the row above. A for loop builds those rows one at a time. The trick is spaces on the left + stars in the middle β as we go down, fewer spaces, more stars, and a triangle appears.
Your turn β try these
- 1Replace "*" with an emoji like "π" or "β" and rerun.
- 2Can you print TWO trees side-by-side on each row?
- 3Add a one-line trunk at the bottom made of "|" characters.