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 :
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"