i want to count and output the amount of times heads and tails are occur in a coin toss based of a users input of amount of coin tosses they want.
so far with this I get no of heads: 1 and no of tails: 1
i also want to get a count of how many coin flip tries it takes to get a list of all heads and then of all tails, but im struggling with this first!
here is my code:
# This program simulates tosses of a coin.
import random
heads = "Heads"
tails = "Tails"
count = 0
def main():
tosses = int(input("Enter number of tosses:"))
coin(tosses)
print("Total number of heads:",(heads.count(heads)))
print("Total number of tails:", (tails.count(tails)))
#end of main function
def coin(tosses):
for toss in range(tosses):
# Simulate the coin toss.
if random.randint(1, 2) == 1:
print(heads)
else:
print(tails)
return (heads.count(heads),(tails.count(tails)))
# end of if statement
#end of for loop
#end of coin function
# Call the main function.
main()
Aucun commentaire:
Enregistrer un commentaire