So, I have a task in which I have to create a program that simulates a flip of a coin, creating a random number corresponding to heads or tails. When three simultaneous "H" (heads) or "T" (tails) are output, my program should stop. I tried to make this work, here is my code:
import random
active=True
list1 = []
b = 0
while active:
l=random.randint(0,1)
b += 1
i='a'
if l == 0:
i = 'H'
else:
i = 'T'
list1.append(i)
if list1[:-3] is ['H','H','H']:
active = False
elif list1[:-3] is ['T','T','T']:
active = False
else:
active = True
print(list1),
It seems that the only thing that doesn't work is the part that checks for the presence of three matching heads or tails, does anyone know how I can correctly encode this part?
source
share