|Random Numbers and Choose|
When you roll a die, you aren't sure what number you will get. You might get a one or a six or a five. This sort of number is called a random number.
In the program area on the left, type "show(random(6));" When you click the Run button, what number is shown? If you run the program several times, you should get lots of different numbers.
Let's write a program for a game show. On this game show, there are three doors: a blue door, a red door, and a purple door. There is a prize behind one of the doors. You can choose to open one door. If the prize is there, you win it!
First, we'll number the doors. The blue door is door 1. The red door is door 2. The purple door is door 3. We can then use random(3) to choose which door has the prize. Remember that random(3) will find a number between 1 and 3, and each door is numbered either 1, 2, or 3.
The program should then ask which door you want to open: the red door, the blue door, or the purple door. We'll use a special command called "choose." With the choose command, you first give a string with some instructions. Then, you put a comma and some more strings with different things that someone can choose. If you take the first string, choose will give you back a one. If you take the second string, choose will give you back a two. If you choose the third string, choose will give you back a three. And so forth.
So the program should ask you to choose a door. We stick the choice in a variable called "you." If "you" has 1, it means the blue door. If "you" has 2, it means the red door. And if "you" has 3, it means purple door.
At the end, the program checks whether the door is the one with the prize behind it. If you opened the door with a prize, the program tells you what the prize is. Try the program out.