Sharedformal pre class work - simulation.ipynbOpen in CoCalc
import random

def inputs():
    a = input("what is the probability that player A will win a serve? ")
    b = input("what is the probability that player B will win a serve? ")
    c = input("number of games? ")
    return a, b, c

def simulation(n, prob_a, prob_b):
    wins_a = wins_b = 0
    for i in range(n):
        score_a, score_b = one_game(prob_a, prob_b)
        if score_a > score_b:
            wins_a = wins_a + 1
        else:
            wins_b = wins_b + 1
    return wins_a, wins_b

def one_game(prob_a, prob_b):
    serving = 'A'
    score_a = 0
    score_b = 0
    while not end_game(score_a, score_b):
        while random.random() < prob_a:
            score_a = score_a + 1
        while random.random() < prob_b:
            score_b = score_b + 1
    return score_a, score_b

def end_game(a, b):
    return a >= 21 or b >= 21



simulation(10000,0.6,0.5)
(8110, 1890)