I'm just getting started with Python, and ran into a problem. I'm writing a function to simulate a coin flip. When I wrote some mock code to test the randint function it worked perfectly fine and returned a nice random sequence of heads and tails. The code I try to use in my program however returns only h's or t's.
import random
coin_sequence = "hhththththhhhttthht"
generated_sequence = "" #define generated_sequence
length = len(coin_sequence)
flip = random.randint(0, 1)
for value in range(length):
if flip == 0:
generated_sequence = generated_sequence + "t"
else:
generated_sequence = generated_sequence + "h"
print(generated_sequence)
I probably made some really stupid mistake. Who can help me?
Aucun commentaire:
Enregistrer un commentaire