from random import randint

n = 1000

dct = {"PP": 0, "FF": 0, "PF": 0, "FP": 0}
gain_dct = {-2: 0, 6: 0, 2 : 0}

gain_total = 0

for i in range(n):
    gain = 0
    p1 = "P" if randint(0, 1) == 0 else "F"
    p2 = "P" if randint(0, 1) == 0 else "F"
    if p1 == "P":
        gain = gain + 3
    else:
        gain = gain - 1
    if p2 == "P":
        gain = gain + 3
    else:
        gain = gain - 1
    res = f"{p1}{p2}"
    dct[res] = dct[res] + 1   
    gain_dct[gain] = gain_dct[gain] + 1
    gain_total = gain_total + gain
    # print(res, gain)
print(dct, gain_dct)

freq = {}
for key in gain_dct:
    freq[key] = gain_dct[key] / n

print(freq)
print(gain_total)
gain_moyen = gain_total / n
print(gain_moyen)

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: