**Originally published in the September 2000 issue of Australia’s Hotsource online newsletter**

Now that most of you can be considered advanced beginners in using MicroWorlds, this issue will explore a bit more of the language and data structures available to you.

The following activity explores probability while demonstrating how sliders, text boxes and even the screen may be used to collect and report data.

**Who’s for two-up?
**The core of this task will be to flip a coin numerous times and record the number of times heads and tails appear.

- Start a new project.
- Name the turtle, coin.
- Create two coin shapes in the shapes centre. Name one heads and the other tails. Be sure to make them appear different in some way so that the user can clearly see which one side of the coin lands faceup.
- Change the turtle’s costui-ne to one of the coin shapes. Create a Many Times button with the instruction, flip.

**Recording data with text boxes
**This part of the project will flip a coin in FLIP, and change the value in the textboxes, headscount, tailscount and totalflips. If you name turtles, text boxes or sliders with unique name you may change them even ii they are on different pages. This allows you to have some action going on between the scenes.

- Make a Startup button on the first page.
- Create a new page from the pages menu.
- Create text boxes named, Headscount, Tailscount and Totalflips.
- Show the names of the text boxes so the user knows what they are reading
- Click the Startup button
- Type the following procedures on the procedures page.

to flip

ifelse coin = ‘heads

[recordheads]

[recordtails]

settotalflips totalflips + 1

end

to coin

if 1 = random 2 [output “heads]

output “tails

end

to recordheads

coin, setsh ‘heads

setheadscount headscount + 1

end

to recordtails

coin, setsh “tails

settailscount tailscount + 1

end

to startup

everyone [settext 0]

end

Click the flip button to start and stop the experiment. You may wish to make the flip button run many times if you want it to keep flipping the coin.

**Recording data with sliders
**Sliders may be used as reporters (input devices) to change the value of a variable or they may be used as indicators (output devices) displaying the current value of that reporter. Let’s experiment with sliders on a second page of our coin flipping project.

- Create a new page from the Pages menu
- Create two sliders ‘heads and tails, with a minimum of 0 and maximum of 300 at the bottom of the new page
- Optional: Create buttons to switch between the two pages of our project.
- Make the following changes to your procedures.

To recordheads

coin, setsh ‘heads

setheadscount headscount + 1

**setheads heads + 1**

end

to recordtails

coin, setsh “tails settailscount tailscount + 1

**settails tails + 1**

end

to startup

settailscount 0

setheadscount 0

settotalflips 0

**settails 0 setheads 0**

end

Type Startup to init-ialise the variables, click oA the flip button and switch between pages.

Do you see the sliders changing their values?

**Extra bonus! Adding a histogram to graph our data
**It is easy to add simple graphing functionality to our probability lab with the creation of two turtles and a bit more Logo programming.

- Hatch two turtles on the same page as the sliders.
- Name one turtle, headsgraph, and the other, tailsgi-aph (for heads graph and tails graph)
- Place those turtles above their respective sliders.
- Create two different turtle costui-nes consisting of blue and red horizontal bars. Name the shapes hline and tline.

Make the following changes to your procedures.

To recordheads

coin, setsh ‘heads

setheadscount headscount + 1

setheads heads + 1

headsgraph, fd 1 stamp

end

to recordtails

coin, setsh “tails

settailscount tailscount+l

settails tails + 1

tailsgraph, FD 1 stamp

end

to startup

settailscount 0

setheadscount 0

settotalflips 0

settails 0 setheads 0

headsgraph, setpos [-170 1451]

tailsgraph, setpos [200 145] page2 clean pagel

end

Type Startup and click on the flip button to set the experiment in action! You may even want to figure out a way to stop the graphing when a bar reaches the top. How about a textbox reporting the experimental standard deviation?

The magic of MicroWorlds’ parallelism allows the coin to be animated, text boxes to change, sliders to report and a histogram to be created all at once. You can use lots of software to generate random numbers, but no other title allows all of these things to happen at once. I am confident that you can figure out exciting ways to integrate these programming techniques into much more complex simulations and experiments.

**Originally published in the September 2000 issue of Australia’s Hotsource online newsletter**

LogoWriter and MicroWorlds have done so much for interdisciplinary projects that it is useful to remember that MicroWorlds can play a major role in the development of mathematical knowledge. This issue and next will explore the numerical side of MicroWorlds.

**First the Boring Stuff**

MicroWorlds procedures come in two categories, commands and procedures. Most Logo-users are quite comfortable with commands such as CG, FD, RT and SETC. Commands may or may not take inputs and they always produce an action. Every Logo expression (line of code) must begin with a command. This is why typing HEADING in the command centre produces the error message I don’t know what to do with HEADING. SHOW HEADING, FD HEADING, RT HEADING * 2 will all work because HEADING reports the turtle’s current orientation and hopes a command is listening. Commands may have any number of hoppers, but they never have a spout. REPEAT is an example of a two input (hopper) command.

Every one input command beginning with the prefix, SET, has a corresponding reporter with no inputs. For example:

Command | Reporter |

SETC | COLOR |

SETH | HEADING |

SETPOS | POS |

SETBG | BG |

SETX | XCOR |

SETTEXT1 | TEXT1 (where text1 is the name of a textbox) |

**At the core of it all
**Reporters are procedures that may or may not take an input, but they always output a result. Reporters are also known as functions or operations. Reporters are absolutely essential for most mathematical and interactive MicroWorlds projects. They pass information that can be used by other procedures or turtles. Reporters may have any number of hoppers, but they always have just one spout.

**It’s your call
**You can write your own reporters if you remember one simple rule. Every reporter procedure contains one output. When Logo encounters the OUTPUT reporter, the procedure is terminated. To create a new reporter you need to remember the rule about OUTPUT and decide how many inputs the reporter needs. For example, if we wanted to write a procedure to double a number, we would only need one input.

to double :number

output :number * 2

end

or

to double :number

output :number + :number

end

Type: DOUBLE 45 in the command centre and see what happens? Why did you receive an error message?

Many people who wish to double a number would write the following procedure.

To dumb.double :number

show :number * 2

end

Then if they type, DUMB.DOUBLE 45 in the command centre they will get what they think is the desired result. This is the result they need only if they want to see the number 90 appear in the command centre.

Try typing the following instructions in the command centre:

FD DUMB.DOUBLE

45 DUMB.DOUBLE DUMB.DOUBLE 45

Now try typing:

SHOW DOUBLE 45

FD DOUBLE 45 RT DOUBLE 45

SHOW DOUBLE DOUBLE DOUBLE 45

Our DOUBLE procedure is much more flexible and versatile than DUMB.DOUBLE.

**They can speak to each other
**Reporters can perform a manipulation/operation on an input and then report that result to another reporter. Logo (MicroWorlds) reads reporters from right to left since you can’t type from top to bottom. The following graphic illustrates FD ADD5 DOUBLE DOUBLE 5.

Logo is a prefix language. That means that inputs always follow the procedures. Since humans like the standard arithmetic operators (+-*/), Logo will tolerate them, but often requires parentheses for grouping. These infix reporters tend to give the turtle indigestion. Logo much prefers PRODUCT 3 4 to 3 * 4. See how SHOW DOUBLE DOUBLE 3 + 4 behaves if you add parentheses, like SHOW (DOUBLE DOUBLE 3) + 4.

**Make it simple
**Young children can use similar simple arithmetic reporters to leverage their own turtle graphics. For example, a child incapable of calculating twice the distance for the turtle travel could use a DOUBLE or TWICE reporter and operate algorithmically. These procedures could be written by a teacher ahead of time or by the student herself.

Operation of fractions may also be explored with simple reporters.

To 3fourths :number

output :number * 3 / 4

end

to 2thirds :number

output :number * 2 / 3

end

to 1half :number

output :number / 2

end

To “play with” multiplication of fractions, try typing:

SHOW 3fourths 100

SHOW 1half 100

SHOW 2thirds 3fourths 100

You may of course use these fractional reporters to command the turtle. Type the following BAR procedure on the procedure page.

To bar :height

pd repeat 2 [fd :height rt 90 FD 25 rt 90]

pu rt 90 FD 35 lt 90

end

See what happens if you type the following in the command centre.

BAR 100

BAR 3fourths

100 BAR 1half 100

BAR 2thirds 3fourths 100

**Battle of the Functions**

You can make a game out of all these arithmetic reporters. Put kids in groups of four or five and have them each contribute one new arithmetic procedure in the style of DOUBLE. They may use their own imprecise names for the reporters if they wish (as long as they can explain its function to their peers). Each kid takes turns inventing a number problem consisting of stacked-up reporters and one numerical input. The object of the game is to invent a problem that is difficult, but not impossible to solve in one’s head. Wiseguys are penalized by the rules of the game.