dimanche 9 juin 2019

is it possible to print everything in total instead of printing the percentage of every action

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)+'%')


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.




Aucun commentaire:

Enregistrer un commentaire