Print a staircase of stars
You will make each output line contain one more star. The pattern comes from repeating a string, so your prediction should include both the rows and their lengths.
- Code
- Explorer
- About 15 minutes
Grown-up needed: yes for choosing and supervising the coding environment
The film says 'Taz, on the Code tab'. In Taz today, choose Make, then Code, and pick Python.
What you need
- Paper and a pencil
- A grown-up-approved Python environment where the steps use code
- A grown-up
- Or the Maker Studio in Taz, in Python mode: open Taz, choose Make, then Code
The rule
Guess the picture before you run it.
How to do it
- Write for n in range(1, 6): on the first line.
- Indent print("*" * n) beneath it.
- Draw the expected five rows on paper.
- Run the program and compare the shortest and longest rows.
- Count the total stars across the output.
Why it works
In this Python expression, multiplying a string by a non-negative integer repeats the string that many times. The loop changes n from one through five, giving successive row lengths of one, two, three, four and five stars. Printing each repeated string starts a separate output line. The resulting staircase is a text pattern rather than a drawing made from coordinates. Its total number of stars is the sum of the row lengths, which is fifteen for this five-row example.
Make it harder
- Make an eight-row staircase.
- Repeat the string ab instead of a star.
- Predict a descending staircase before changing the range.
Ask Taz
- Why does multiplying text repeat it?
- Why are there fifteen stars in five rows?
- Why does a longer repeated string change the row width?
The coding part of Taz is the Maker Studio.
For grown-ups
Choose and supervise the coding environment. The film names a Taz Code tab. In Taz today that is the Maker Studio: choose Make, then Code, and pick Python. Use ordinary sample words and numbers without personal details. Ask at dinner: “Which prediction did you check, and what change in the instructions would change that output?”
Taz is an AI and can be wrong, so stay close by. Read how safety works on Taz.
Show us yours
Film your hands and what you made, not your face or name. Ask a grown-up before posting anywhere else.
Questions parents ask
Can we begin without running code?
Yes. Write the predicted output on paper and trace the steps together. That gives you a comparison to use when a grown-up-approved Python environment is available. A prediction remains a prediction until you check the actual instructions and result.
What if an error appears?
Read the message with a grown-up and compare spelling, punctuation and indentation with the steps. Change one thing at a time and keep a note of what happened. An error is useful evidence about the instructions, not a judgement about the child.
Must we share the result?
No. Discussing the output at home is enough. Follow the privacy line above for optional online sharing.
More to try
See all Taz Challenges, or look through the science labs. One place for every why. Ask for early access at aitaz.com