Coin Flip Simulation

Coin Flip Simulation – Write some code that simulates flipping a single coin however many times the user decides. The code should record the outcomes and count the number of tails and heads.

"""
Q: Coin Flip Simulation - Write some code that simulates flipping a single coin however many 
   times the user decides. The code should record the outcomes and count the number of tails and heads.
"""
import random

def Coin_Flip_Simulation(times):
    
    heads = 1
    tails = 0
    
    for t in range(0,times +1):
        event = random.choice([0,1])
        if event == 0:
            tails += 1
        elif event == 1:
            heads += 1

    print(f"Number of tails is: {tails}\
            \nNumber of heads is: {heads}")

    
times = int(input("Enter the number of time you want you flip coin: "))
Coin_Flip_Simulation(times)

Leave a comment