📜  coinflip - Python (1)

📅  最后修改于: 2023-12-03 15:30:03.099000             🧑  作者: Mango

Coinflip - Python

Coinflip is a simple Python program that simulates a coin toss. It is a great example of how to use Python's random module and basic input/output functions.

Usage

To use Coinflip, simply run the program in a Python interpreter or IDE. Once the program is running, it will ask you to input either "heads" or "tails" and then perform a coin flip. If the result matches your choice, the program will print "You Win!"; otherwise, it will print "You Lose."

Here is the code that runs Coinflip:

import random

def coinflip():
    guess = input("Heads or Tails?: ")
    result = random.choice(["Heads", "Tails"])
    if guess == result:
        print("You Win!")
    else:
        print("You Lose.")
Example Output

Here is an example of what you might see when running Coinflip:

> python coinflip.py
Heads or Tails?: Heads
You Lose.
> python coinflip.py
Heads or Tails?: Tails
You Win!
Summary

In summary, Coinflip is a simple and fun example of how to use Python's random module and basic input/output functions. It is a great program for beginner Python programmers to learn from and build upon.