Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://automatetheboringstuff.com/2e/chapter4/
- # project 2 Coin Flip Streaks ver. 3
- import random
- numberOfStreaks = 0
- runs = 10000
- flips_per_run = 100
- streakLength = 6 # how many streaks to look for
- for i in range(runs):
- # Code that creates a list of 100 'heads' or 'tails' values.
- flipsList = []
- for i in range(flips_per_run):
- flipsList.append(random.choice(['H', 'T']))
- # Code that checks if there is a streak of 6 heads or tails in a row.
- for i in range(len(flipsList)):
- if flipsList[i:i+streakLength] == list(streakLength * 'H') or flipsList[i:i+streakLength] == list(streakLength * 'T'):
- numberOfStreaks +=1
- print('Chance of streak: %s%%' % (numberOfStreaks / runs))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement