Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I need to calculate percentage of tails/heads

I need to calculate percentage of tails/heads. I wrote a part of the code that works but not the way it should! the more heads or tails I get, the less chance they get! How can I solve the problem? Here is part of the code I wrote.

throws=[]
while True:
    throw=input("You flip the coin and it was?Head/Tail: ")
    throws.append(throw)
    total_flips=len(throws)
    heads_count=throw.count("head")
    tails_count = throw.count("tail")

    heads_percentage=(heads_count/total_flips)*100
    tails_percentage = (tails_count/total_flips) * 100
    match throw:
        case "head":
            print(f"Percent of head:{heads_percentage}%")
        case "tail":
            print(f"Percent of tail:{tails_percentage}%")

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Should change below from "throw" to "throws" because count should work at the list

    heads_count = throws.count("head") # origin code "throw"
    tails_count = throws.count("tail") # origin code "throw"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading