In this activity you will write programs that simulate the game of baseball, in terms of different kinds of base hits, runners on bases, outs, and runs scored. Your program must set variables hits, runs, and outs, all of which are numbers; and on_base, which is a list of boolean (True or False) values. For example [ False, True, True ] means that there's no one on first base, but runners on second and third.

The example program below runs through an inning, with all of the hits and outs known in advance. Run it by clicking Animate, and see how the scoreboard updates as the program progresses.

on_base = [ False, False, False ] runs = 0 hits = 0 outs = 0 hits += 1 on_base[0] = True print "Single" outs += 1 print "Out ", outs hits += 1 on_base = [ False, True, True ] print "Double" outs += 1 print "Out ", outs hits += 1 runs += 2 on_base = [ False, True, False ] print "Double" outs += 1 print "Out ", outs