Half the time
Page 5: Adding Variety to Gossip
Unit 1, Lab 2, Page 5
On this page, you will improve your program so that sometimes the sentences are a bit longer and more complex.
The block has been built for you (look through the blocks to find it) (hint: what colour is this block? where are all blocks of that colour contained?). It randomly chooses 1, 2, 3, or 4, and if that number is 3, then it reports something more complicated than who
. Otherwise, it reports who
, just as before.
If it isn’t open already, open your U1L2-Gossip project.
Find in the red Lists palette, drag it into the scripting area, and click on it enough times to see how it’s different from
who
.Here is the code for
more complicated who
. There are two new things in it:pick random
andif else
.- Find in the green Operators palette, and click it several times. What does the
random
block do? - In the
more complicated who
block, what happens if thepick random
block picks 3? What if it picks 4?
- Find in the green Operators palette, and click it several times. What does the
-
About how often will
more complicated who
pick the more complicated choice?If a number is chosen randomly from 1, 2, 3, and 4, about how often will that number be 3?
A third of the time
If a number is chosen randomly from 1, 2, 3, and 4, about how often will that number be 3?
A quarter of the time
Correct!
Three quarters of the time
If a number is chosen randomly from 1, 2, 3, and 4, about how often will that number be 3?
Here is the script inside
more complicated who
. What change to this script will make the more complicated phrase appear more often?Change the 4 to 5.
Then three will be the randomly chosen number one out of five times instead of one out of four, and so we’ll have a complicated subject less often.
Change the 4 to 3.
Correct! Three will then be the chosen number one out of three times, and so we’ll have a complicated subject more often.
Change the 3 to 1.
1 is just as likely a random choice as 3, one out of four times, and we’ll have a complicated subject just as often as before.
Change the 3 to 5.
The chosen number can never be 5, so we’ll never get a complicated subject.
: Expressions and Values
- An expression is a either a constant value (such as “4” or “winter”) or a call to a reporter block including its inputs (such as , , or ).
- Expressions are evaluated to produce a single value (a value can be a number, a string, a sprite, a costume, a script, a list—anything). For example, will be evaluated to 17.
The expression would be written as
RANDOM(1, 10)
or . Every time you run this code, you will get a different random number between 1 and 10.
-
Click for a review of odd and even numbers.
An even number is an integer that is divisible by 2 (such as 2, 14, 0, -4, -6, -28, and -176).
In contrast, odd numbers are integers not divisible by 2 (such as 1, 3, 9, 17, -5, -33, and -221).
Which expression will return a random even number between 1 and 10?
RANDOM(2, 10)
RANDOM(2, 10)
will return 2, 3, 4, 5, 6, 7, 8, 9, or 10.
2 * RANDOM(1, 5)
Correct!
RANDOM(1, 5)
will return 1, 2, 3, 4, or 5, and so
2 * RANDOM(1, 5)
will return 2, 4, 6, 8, or 10.
RANDOM(1, 10) / 2
RANDOM(1, 10)
will return 1, 2, 3, 4, 5, 6, 7, 8, 9, or 10, and so
RANDOM(1, 10) / 2
will return ½, 1, 1 ½, 2, 2 ½, 3, 3 ½, 4, 4 ½, 5.
RANDOM(1, 5)
RANDOM(1, 5)
will return 1, 2, 3, 4, or 5.
Which expression will simulate the rolling of two dice?
RANDOM(1, 6) + RANDOM(1, 6)
Correct!
RANDOM(1, 6)
will return 1, 2, 3, 4, 5, or 6 with equal probability, simulating one die, and so
RANDOM(1, 6) + RANDOM(1, 6)
will return 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, or 12 with the same probability as two dice.
2 * RANDOM(1, 6)
You have the right idea, using
RANDOM(1, 6)
for the roll of a single die. But this expression doesn’t roll two dice; it rolls one die and doubles the result. So
2 * RANDOM(1, 6)
will only return 2, 4, 6, 8, 10, or 12.
RANDOM(2, 12)
RANDOM(2, 12)
will return 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, or 12 equally often. Do you score 2 rolling two dice as often as you score 6?
RANDOM(1, 12)
Can you score a total of 1 by rolling two dice?
Create a new block that is similar to
gossip
but that usesmore complicated who
instead ofwho
. (You can choose whichwho
to replace, or you could replace both.)Change the script for Sprite to use
complicated gossip
instead ofgossip
. Run your code, and fix any problems.
Making a Block Call Itself
Edit
more complicated who
. Replace one of thewho
blocks with a fresh copy ofmore complicated who
that you drag in from the palette. Clickmore complicated who
enough times to see how it has changed.Discuss the the change in behavior with your partner, and explain what you think is causing it.
- Make Sprite(2) occasionally give a more complicated reply.
Purple “Take It Further” boxes have more challenging activities that are not required. If you finish everything else on the page early, try these instead of jumping ahead to the next page.
-
Make
more complicated who
give the more complicated response three out of four times instead of one out of four times. - What happens when you try it out? Was it what you expected? Explain why it happened.