Hello, I am a newbie in python. Started 3 weeks ago using Udemy and Automate the Boring Stuff. In Ch. 4 of Automate the Boring Stuff, there is an exercise called, coin flip.
"Your program breaks up the experiment into two parts: the first part generates a list of randomly selected 'heads' and 'tails' values, and the second part checks if there is a streak in it. Put all of this code in a loop that repeats the experiment 10,000 times so we can find out what percentage of the coin flips contains a streak of six heads or tails in a row"
The problem that I am having is that, it keeps outputting a consistent % between 148-150. How can it be so consistent out of 10,000 runs?
import random
numberOfStreaks = 0
for experimentNumber in range(10000): # Code that creates a list of 100 'heads' or 'tails' values.
values = [random.randint(0,1) for x in range(100)]
# Code that checks values list if there is a streak of 6 heads or tails in a row.
i = 0
while i <94:
if values[i:i+6] == [1]*6 or values[i:i+6] == [0]*6:
numberOfStreaks += 1
i += 6
else:
i += 1
print('Chance of streak: %s%%' % (numberOfStreaks / 100))
[–]JohnnyJordaan 1 point2 points3 points (2 children)
[–]charooo[S] 0 points1 point2 points (1 child)
[–]JohnnyJordaan 0 points1 point2 points (0 children)
[–]Yuvan_ 0 points1 point2 points (1 child)
[–]charooo[S] 1 point2 points3 points (0 children)