I'm a Beginner; I'm trying to make a program in python 3.5 that flips a coin 100 times, then counts the amount of heads and tails from those 100 flips and displays it at the bottom. I got the 100 flips to work, and I also tried to make a counter to count the amount of h/t that landed, but it's inconsistent and wonky, and the counters doesn't count the correct amount. I would love it if some one could help me.
import random
hcounter = 0
tcounter = 0
while True:
flip = ['heads','tails']
decision = input("Flip a coin 100 times? (y/n): ")
if decision == 'y':
#for some reason, the range doubles the number; I dont know why, so since I want 100 flips, I put 50 for the range.
for x in range(0, 50):
for y in flip:
print(random.choice(flip))
if random.choice(flip) == flip[0]:
hcounter += 1
elif random.choice(flip) == flip[1]:
tcounter += 1
print("--------------------------------")
print("Heads: ",hcounter,"\nTails: ",tcounter)
elif decision == 'n':
print("\nOk")
break
yeah