Student Login

Coding Activity #4

You’ve been challenged by your friend Toad to predict the future. Will this help you to defeat Bowser?

Activity #4 - Better Guesses

You’ve been challenged by your friend Toad to predict the future. He feels it will help give you a tool to defeat Bowser when you need to in one of his games of chance.

  • Ontario curriculum alignment:  Grade 6
  • Best for:  Intermediate coders of all grade levels!

Before you begin ...

This hands-on activity uses a free coding platform called "Scratch". Please make sure you've watched our "Introduction to Scratch" video, and that you're signed into your Scratch account. If you need help, click below. Otherwise, skip down to STEP 1 to get started!

Open the Scratch activity

Click the button below to open the activity. It will open in a new window/tab which allows you to keep this page open at the same time and easily switch between tabs while you work through this activity.

  • After you open the activity, click on the blue "See inside" button to access the activity.
  • If you are logged into your Scratch account, then you can click on the green "Remix" button to save this activity to your personal Scratch account so you can save your work and also share it with others!
Open the activity

Watch this video

The magic brick

Level 1

You’ve been challenged by your friend Toad to predict the future. He feels it will help give you a tool to defeat Bowser when you need to in one of his games of chance. To practice, he’s also given you a magic brick that will make random selections for you when you jump and hit it, which in this level simply chooses a random number between 1 and 100.

Toad has explained that when you select any random number, it can be large or small but over enough time, if you average them together, a given range of numbers will always settle around one value. It’s like predicting the future! We can’t predict each number, because they’re random, but we can predict their average.

Example

Let’s take a look at the numbers 15, 90 and 37. They have an average of: 15+90+78 / 3 = 61. You’ll notice 61 is kind of in the middle of all of those numbers. This value helps you understand the probability of getting a certain range of numbers.

Your first task is to guess what the average number will be over time for your brick of 1 to 100. Follow the instructions below to get started at this level.

  1. Use the “A” and “S” keys to position the red rectangle to make your guess. You’re allowed to be a bit off, but not too much!
  2. Set your guess of the red rectangle and don’t move it until you run your test.
  3. The green arrow will show you the average of all the numbers you’ve selected so far as you run your test.
  4. By jumping with Mario, hit the brick 25 times and see if the average is close enough to your guess and inside the red rectangle.
  5. There is a note in the brick sprite code where you can change the number to be 1 to something else instead of 100. Change it to a new number like 70 or 80 and make a new guess using the red rectangle!

Follow-up Questions

  1. What value does the average (green arrow) seem to be approaching the more numbers you select?
  2. How does the arrow behave when you first start selecting numbers? Does that change over time?
  3. What happens to the average when a large number is chosen? What about a very small number?
  4. Imagine a game where you win every time the number is less than the average and you lose every time it is greater than the average. How often will you win?

When you’ve completed this level, watch the next video below.

Watch this video

Code your own game of chance!

Level 2

Now it’s your turn to code your own game of chance! We have already got you started by creating variables for “Heads” and “Tails” and giving them values of 1 and 2, respectively. We have also created the variables “Head Count” and “Tail Count” which store the number of heads and tails that you have selected.

Follow the instructions below to get started at this level.

  1. Click on the “Green Flag” and press “L” on your keyboard, followed by “2” to enter Level 2 of this game.
  2. Select the coin “Quarter” sprite. Your new code will go inside the “If Level = 2” block.
  3. Using the blocks provided in the sprite, create code that does the following behaviours:
    a)  If a random choice between heads and tails gives you heads, then switch the costume to heads and also change the “Head Count” variable by one.
    b)  Else (or otherwise) switch the costume to tails and increase the “Tail Count” variable by one.
  4. Once your code is working, as before, move the red selecter where you think the average will be.
  5. Jump and hit the brick 25 times and see if your guess is correct.

When you’ve completed this level, watch the next video below.

Watch this video

It's us against Bowser once again!

Level 3

Our fears were justified, Bowser has come for us! Good thing we’ve been practicing our skills! Let us see if we can trick him by telling him we can predict the future. Bowser has come with his own game and it seems to work like this: He gets all the black cards, AND he also gets all the red face cards as well (Jack, Queen, King, and Ace). We only get the other red cards. Good luck defeating Bowser, even though you don’t need it!

Time to do some math. Knowing that there are 52 cards in a deck, and that there are 13 of each suit, how many cards make us win? How many cards make Bowser win? Use the following equation to help you calculate the probability of winning this game against Bowser.

The averages we’ve been calculating for the past 2 levels are as follows:

  • Level 1 - Random Number from 1 - 100: There were 50 ways to win (numbers 1-50 or numbers 51-100) and 100 total options.
  • Level 2 - Coin Flip: There was 1 way to win and 2 total options (heads or tails).

The probability is usually ½ or 0.5 for both levels and the average will eventually always get close to the probability the more tests you do.

Using the equation and the math notes above, follow the instructions below to complete level 3:

  1. Click on the “Green Flag” and press “L” on your keyboard, followed by “3” to enter Level 3 of this game.
  2. Calculate the probability you have of winning and what the average outcome will be after 25 card selections.
  3. Put the new smaller purple selecter where you think it will be, knowing your probability calculation from #2 above.
  4. Hit the brick 25 times to draw your cards.

#207 - 8501 - 162nd Street
Surrey, British Columbia
Canada  V4N 1B2

Parents

Learn More
Book Samples
Online Platform
Pricing
Online Store
Free Trial

Teachers

Learn More
Book Samples
Teacher Resources
School Pricing

About

About Us
Contact
Privacy Policy
Cookie Policy
Terms & Conditions