BaşlayınÜcretsiz Başlayın

Betting between Tom and Eva

It's time to play a game between Tom and Eva!

Recall that Tom has a regular six-faced die and the results of rolling it follow a discrete uniform distribution in the interval of one and six. Eva has a biased coin that has a probability p of turning heads. The distribution of the number of flips Eva needs to land heads is geometric.

Here are the rules of the game:

  • Tom's score: the point of the rolled die
  • Eva's score: the number of flips needed to land heads
  • The person with the highest score wins

Your task is to simulate this game! For the list of possible p values [0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 0.9] representing the probability of Eva's coin flipping heads, who do you expect to win?

NumPy has been imported as np and SciPy's stats module as st.

Bu egzersiz

Monte Carlo Simulations in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Simulate rolling Tom's die 10,000 times, assigning the results to die_samples.
  • Simulate Eva's coin flips to land heads 10,000 times, assigning the results to coin_samples.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

for p in [0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 0.9]: 
    low = 1
    high = 7
	# Simulate rolling Tom's die 10,000 times
    die_samples = ____
	# Simulate Eva's coin flips to land heads 10,000 times
    coin_samples = ____
    diff = np.mean(die_samples - coin_samples)
    print(diff)
Kodu Düzenle ve Çalıştır