Code a dice
You will generate ten numbers between one and six and record each result. A short run can have repeats and uneven totals, just as a real die can.
- Code
- Starter
- 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
Run it ten times. Tally the results.
How to do it
- Write import random on the first line.
- Write print(random.randint(1, 6)) on the second line.
- Prepare six tally columns labelled one through six.
- Run the program ten times and add one mark each time.
- Check that the column totals add to ten.
- Compare with ten gentle rolls of a die in a tray.
Why it works
The randint function selects an integer from the stated range, including both one and six. Python’s usual random generator produces a pseudorandom sequence, generated by an algorithm, suitable for this simple exploration rather than a guarantee about security. Repeated values are allowed. Ten runs are too few to expect each face equally often, and even larger samples need not divide perfectly. Your tally records what happened in this run rather than predicting the exact next result.
Make it harder
- Record twenty runs instead.
- Compare two separate sets of ten.
- Explain why six different possible outcomes do not require equal tallies.
Ask Taz
- Why can the same number appear twice?
- Why does ten runs give an uneven tally?
- Why is a computer-generated sequence called pseudorandom?
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
Try it in 3D: Probability.