#!/usr/bin/env python #------------------------------------------------------------------ # tosscoin.py # # This program uses the 'sleep()', 'flush()' and 'randint()' # Python functions in a computer simulation of coin-tossing. # # execute using: $ python tosscoin.py # # programmer: ALLAN CRUSE # written on: 23 JAN 2011 #------------------------------------------------------------------ import time # for sleep() import sys # for flush() import random # for randint() # announce the simulation print "\nNow tossing a coin ", # create the visual delay time.sleep( 0.10 ) for x in range(0,8): time.sleep( 0.10 ) print ".", sys.stdout.flush() time.sleep( 0.10 ) # genrate a random result: zero or one y = random.randint(0,1) # output the result's interpretation if ( y > 0 ): print " HEADS" else: print " TAILS" print