import random class Player: """A player in a racquetball game.""" def __init__(self, win_prob): """Constructor. win_prob is the probability that this player wins the point when she serves.""" self.win_prob = win_prob def serve(self): """Simulates one round of play in the game, with this player serving. Returns whether this player won this serve: True if so, False if not.""" return (random.random() < self.win_prob) def main(): alice = Player(0.8) num_wins = 0 for game_number in range(10000): if alice.serve(): num_wins += 1 print "Alice won", num_wins, "games out of 10000." if __name__ == "__main__": main()