我正在尝试编写一个程序,以找出在随机生成的 100 次翻转的正面和反面列表中出现六个正面或六个反面的条纹的频率,并重复此 10000 次以查找硬币翻转的百分比连续包含六个正面或反面。
我的代码是这样的,它是某种工作。**我想知道它是否给出了正确的结果:**
import random
numberOfStreaks = 0
# Code that creates a list of 100 'heads' or 'tails' values.
for experimentNumber in range(10000):
results = []
for experiment in range(100):
x = random.randint(1, 2)
if x == 1:
results.append('H')
else:
results.append('T')
# Code that checks if there is a streak of 6 heads or tails in a row.
currentStreak = 0
previousResult = results[0]
for result in results:
if currentStreak == 6:
numberOfStreaks += 1
currentStreak = 0
if result == previousResult:
currentStreak += 1
previousResult = result
print('Chance of streak: %s%%' % (numberOfStreaks / 100))
holdtom
慕慕森
噜噜哒
相关分类