我想知道如何在擲硬幣模擬器中計算結果的可能性。頭部有50%的可能性和50%的尾巴。 我會如何解決返回結果的可能性? 這裏是我的代碼:查找概率
您在模擬已經得到了結果的import random
head = 0
tail = 0
length = int(input('How many coins do you want to flip? '))
for i in range(length):
side = random.randint(0, 1)
if side == 1:
head = head + 1
else:
tail = tail + 1
print('There where ' + str(tail) + ' tails and ' + str(head) + ' heads')
您是否想要測量在給定模擬次數的情況下獲得相同數量的正面和反面的概率? – fulaphex
說你翻了10次我想告訴你它給出的尾部數量的概率,然後是頭部的數量 – Monkeybike123
你要我告訴你:有p1的概率,有1尾,p2會有兩個尾巴...? – fulaphex