Sup Forums Need quick help...

Sup Forums Need quick help. How to make python program which calculates chances of coin falling on head 10 times in a row out of 100 flips? Only using for and while loops

Other urls found in this thread:

math.stackexchange.com/questions/489055/flipping-heads-10-times-in-a-row
twitter.com/NSFWRedditGif

codechef?

just google python coin flipping code, bellend

try:
10 PRINT "HELLO"
20 GOTO 10

hello?
dafuq

underage

>10 times in a row
I wonder if it will. Once wrote a coin flipper and found out the RNG wouldn't do more than 8 in a row.

So what is the exact restriction? You are not allowed to use arithmetic operators?

i can use pretty much everything, want to solve it without using lists, functions, etc.

print("50%")

First things first, what vesrion? I only do 3.X but you can use my version and edit it slightly fir 2.7.
Also, have you tried anything yet or are just begging?

this

So you want to calculate the chances based on simulations?

this

does this help?

math.stackexchange.com/questions/489055/flipping-heads-10-times-in-a-row

Given X be a random variable counting the number of H with probability p as results of n coin flips, the distribution of X is given as a Binomial(n,p). Hence,

Probability[X = x | n,p] = Comb(n,x) * p^x * (1 - p)^(n - x);

where Comb(a,b) represents the combination as the binomial coefficient.
= a!/[(a - b)! * b!]

Then your inputs would be n = 100, p = 0.5 for a fair coin and x = 10.

The next step would be to calculate the binomial coefficient. Probably you could use a library already written, but if there is need to write your own code I would suggest recursive functions rather than loops.

The rest is trivial, just product the outputs.

it does thanks, couldn't find it b4

kek

Chance of x happening to the power of how many times in a row?

I will do it in pseudocode so you at least put a bit of effort into writing the program.

VAR headTemp, headStreak, tenHeads
FOR i = 1 TO 100, i++
flip = RAND[0 to 1]
IF flip < 0.5
headTemp++
IF headTemp > headStreak
headStreak = headTemp
END IF
ELSE
headTemp = 0
END IF
IF headStreak = 10
tenHeads++
headStreak--
END IF
END FOR
PRINT tenHeads + "%"

bump