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 more complicated who 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.

  1. If it isn’t open already, open your U1L2-Gossip project.

  2. Find more complicated who 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.

  3. Here is the code for more complicated who. There are two new things in it: pick random and if else. more complicated who {
if (pick random (1) to (4)) = (3) {
report (join (who) (' who') (does what) ( ) (who))                                                                                          
} else {
report (who)
}
}

    1. Find pick random (1) to (10) in the green Operators palette, and click it several times. What does the random block do?
    2. Talk with Your Partner In the more complicated who block, what happens if the pick random block picks 3? What if it picks 4?
  4. more complicated who {
if (pick random (1) to (4)) = (3) {
report (join (who) (', who') (does what) ( ) (who) (,))                                                                                          
} else {
report (who)
}
} About how often will more complicated who pick the more complicated choice?

    Half the time

    A third of the time

    A quarter of the time

    Three quarters of the time

    more complicated who {
if (pick random (1) to (4)) = (3) {
report (join (who) (', who') (does what) ( ) (who) (,))                                                                                          
} else {
report (who)
}
} 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.

    Change the 4 to 3.

    Change the 3 to 1.

    Change the 3 to 5.

: 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 number, 5 + (4 * 3), or join (who) ( ) (does what) ( ) (who)).
  • 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, 5 + (4 * 3) will be evaluated to 17.

The expression pick random (1) to (10) would be written as

RANDOM(1, 10)

or RANDOM(1, 10). Every time you run this code, you will get a different random number between 1 and 10.

  1. 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)
    2 * RANDOM(1, 5)
    RANDOM(1, 10) / 2
    RANDOM(1, 5)

    Which expression will simulate the rolling of two dice?

    RANDOM(1, 6) + RANDOM(1, 6)
    2 * RANDOM(1, 6)
    RANDOM(2, 12)
    RANDOM(1, 12)
  2. Create a new block complicated gossip that is similar to gossip but that uses more complicated who instead of who. (You can choose which who to replace, or you could replace both.)

  3. Change the script for Sprite to use complicated gossip instead of gossip. Run your code, and fix any problems.

Save your work

Making a Block Call Itself

  1. Edit more complicated who. Replace one of the who blocks with a fresh copy of more complicated who that you drag in from the palette. Click more complicated who enough times to see how it has changed.

  2. Discuss the the change in behavior with your partner, and explain what you think is causing it.

  1. 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.

  1. Make more complicated who give the more complicated response three out of four times instead of one out of four times.
  2. What happens when you try it out? Was it what you expected? Explain why it happened.