from math import *

# calculate the p.m.f. of the poisson random variable with mean mu for values 0 up to L
def poissonpmf(mu, L):
    P = [0]*(L + 1)
    P[0] = exp(-mu)
    for i in range(1, L + 1):
        P[i] = P[i-1] * mu / i
    return P

# code for the barista jam example
def baristajamc():
    prob = 0.0
    xlimit = 7                      # largest value of x needed
    ylimit = 3                      # largest value of y needed
    f = poissonpmf(2, xlimit)       # p.m.f. of random variable X
    g = poissonpmf(3, ylimit)       # p.m.f. of random variable Y
    for x in range(xlimit):
        for y in range(ylimit):
            if 15*x + 30*y < 120:
                prob = prob + f[x] * g[y]
    return prob
