create a python code for mini coin
Creating a mini coin game in Python can be a fun project! Below is a simple console-based mini coin flip game where a player can flip a coin and guess whether it will land on heads or tails. The game keeps track of the player's score based on correct guesses.
Here's a basic implementation:
```python
import random
def flip_coin():
"""Simulates flipping a coin."""
return random.choice(['Heads', 'Tails'])
def play_game():
"""Main function to play the coin flip game."""
score = 0
rounds = 5 # Number of rounds to play
print("Welcome to the Mini Coin Flip Game!")
print("You will have", rounds, "rounds to guess the coin flip.")
for round_number in range(1, rounds + 1):
guess = input(f"Round {round_number}: Guess 'Heads' or 'Tails': ").strip().capitalize()
if guess not in ['Heads', 'Tails']:
print("Invalid guess! Please enter 'Heads' or 'Tails'.")
continue
result = flip_coin()
print(f"The coin landed on: {result}")
if guess == result:
score += 1
print("Correct guess! Your score is now:", score)
else:
print("Wrong guess! Your score remains:", score)
print("Game over! Your final score is:", score)
if __name__ == '__main__':
play_game()
```
### How to Run the Game:
1. Copy the code into a Python file, e.g., `mini_coin_game.py`.
2. Run the file using a Python interpreter:
```bash
python mini_coin_game.py
```
### Game Rules:
- The player will be prompted to guess whether a coin will land on Heads or Tails.
- The game will simulate flipping the coin, and the player will receive feedback on whether their guess was correct.
- The game consists of a set number of rounds (5 in this example), and the player's score is updated based on their correct guesses.
- At the end of the game, the final score will be displayed.
Feel free to modify the number of rounds or any other part to customize the game to your liking!