Terrapin Resources

Coin Flips

Have you ever wondered, when you flip a coin, whether a coin falls more often on the head or the tail? How often would you have to flip the coin to achieve a probability of 50 percent (both sides fall equally often)?

Probability theory says it should be even but the experiment shows it rarely comes out even. This should lead into a discussion of what is the value of the theory, perhaps other than benefitting a casino?

Well, here is the program to help you out. Load the program and enter COINFLIPS and the number of times, preferably not more often than 700 times. The program prints each flip and summarizes the result at the end.

COINFLIPS.lgo

TO MAIN
    CLEARTEXT
    PR [ENTER COINFLIPS FOLLOWED BY THE DESIRED NUMBER BUT NOT MORE THAN MAX OF 700]
END

TO COINFLIPS :NUM
	IF :NUM > 700 THEN PR [DO NOT USE A NUMBER GREATER THAN 700.] STOP
    IF :NUM < 1 THEN PR [USE A NUMBER GREATER THAN 0.] STOP
    PR (SE [TOSSING A COIN] :NUM [TIMES. PLEASE WAIT...])
    PR []
    MANY.FLIPS :NUM 0 0
END

TO MANY.FLIPS :NUM :HEADS :TAILS
    IF :NUM = 0 THEN PR [] PR (SE [HEADS =] :HEADS [.....] [TAILS =] :TAILS) STOP
    IF FLIP = "HEADS THEN PRINT "H MANY.FLIPS :NUM - 1 :HEADS + 1 :TAILS ELSE PRINT "T MANY.FLIPS :NUM - 1 :HEADS :TAILS + 1
END

TO FLIP
    OUTPUT PICK.ONE [HEADS TAILS]
END

TO PICK.ONE :OBJECT
    ; ----------------------------------
    ; picks one item from a word or list
    ; ----------------------------------
    OUTPUT ITEM (RANDOM COUNT :OBJECT) :OBJECT
END

TO REM :COMMENTS
END

MAIN


Procedure MAIN, COINFLIPS
Description Flip a coin to see how often heads or tails will fall.
Level Beginner
Tags Math, Random