Flip coin till 3 heads or 3 tails in a row - help with my code?
Hi guys - I wrote this code (named "3heads" in Code Playground) where the computer should flip a coin consecutively till they get 3 of the same results in a row. Technically it runs, but I don't think it runs right because my "while" loop is wrong. Everytime, I get results in less than 5 flips, so what am I doing incorrectly? Code is named "3heads" in the playground - I don't know how to link it directly here. Thanks! ------ #run program till you get 3 heads or 3 tails in a row consecutively import random sides = ["heads", "tails"] i = 0 while i<10: flip1 = random.choice(sides) flip2 = random.choice(sides) flip3 = random.choice(sides) if flip1 != flip2 and flip2 != flip3: print(flip1, flip2, flip3) i += i elif flip1 == flip2 and flip2 == flip3: print(flip1, flip2, flip3) break