Simulate Coin Toss

Write a Python program that uses the random module to simulate the toss of a coin. The function coin_toss() should return “Heads” or “Tails”.

Example 1:

Input: coin_toss()
Output: "Heads" or "Tails"

Example 2:

Input: coin_toss()
Output: "Heads" or "Tails"

Use the random.choice() method from the random module.

import random

def coin_toss():
    return random.choice(["Heads", "Tails"])

# Test the function
print(coin_toss())
print(coin_toss())

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!