I tried to code a coinToss simulator which was pretty easy for a beginner but then, I tried implementing a percentage system that calculates how much percentage of the total flips were heads or tails. That's when I noticed that i'm stuck and that I probably need some help.
I tried breaking the for loop and excluding everything from x variable to print
import random heads = "Heads" tails = "Tails" flips = int(input("How many flips do you want to toss?: ")) print("................................") cointoss = [(heads), (tails)] for flips in range(flips): toss = random.choice(cointoss) print(toss) X = toss.count(heads) Y = toss.count(tails) Z = 100/(int(X)+int(Y)) print('Percent of X: '+str(X*Z)+'%') print('Percent of Y: '+str(Y*Z)+'%')
this is the result
How many flips do you want to toss?: 4 ................................ Heads Percent of X: 100.0% Percent of Y: 0.0% Heads Percent of X: 100.0% Percent of Y: 0.0% Heads Percent of X: 100.0% Percent of Y: 0.0% Tails Percent of X: 0.0% Percent of Y: 100.0%
I want the code to show the total percentage of the whole loop instead of it showing 100% for either heads or tails based on the outcome.