CSC 161 Lecture 6: CSC 161 (1)

18 views3 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions