CSC 161 Lecture 6: CSC 161 (1)
Document Summary
From random import random def print_summary (wins_a, wins_b): n = wins_a + wins_b. Print ( "wins for b: {0} ( {1:0. 1%} )" . format(wins_b, wins_b / n)) def is_game_over (score_a, score_b): # return true # game is not over. Return score_a == 15 or score_b == 15 def sim_one_game (prob_a, prob_b): score_a = 0 score_b = 0 server = "a" While not is_game_over(score_a, score_b): # change "true" is game is over to false. If random() < prob_a: # wins the serve score_a = score_a + 1. Else : # lost the serve server = "b" If random() < prob_b: # wins the serve score_b = score_b + 1. Else : # lost the serve server = "a" # initialize wins_a and wins_b to zero wins_a = 0 wins_b = 0. # simulate a single game score_a, score_b = sim_one_game(prob_a, prob_b) If score_a > score_b: wins_a = wins_a + 1.