硬币投掷的次数越多,正反面的概率越趋向于二分之一。
import random
countback = 0
countfront = 0
a = int(input('输入次数:'))
for i in range(0,a):
result = random.randint(0,1)
if result == 0:
countfront += 1
print(result)
else:
countback += 1
print(result)
print('结果是')
print('正面:',countfront)
print('反面:',countback)