← Back
Code Challenge 2.6 - Heads or Tails 🪙
Objectives
Your task is to create a program that lets the user play a game of Heads or Tails. Along with the core game, your program should keep track of wins and losses, and ask the user if they want to play again.
Skills to Practice
- Generating random numbers to simulate the coin flip.
- Using loops to repeat the game until the user wants to stop.
- Making decisions with if statements.
Challenge Tasks
- Create a console project named Challenge 2-6.
- Create a program where the user can play Heads or Tails by guessing the outcome of a coin flip.
- Keep track of the number of games won and lost by the user.
- After each game, ask the user if they want to play again. If they choose to continue, repeat the game. If not, end the program and display the total wins and losses.
Sample Output
Welcome to Heads or Tails! 🪙
Guess the outcome (heads/tails): heads [Enter]
It's heads! You win!
Wins: 1 | Losses: 0
Do you want to play again? (yes/no): yes [Enter]
Guess the outcome (heads/tails): tails [Enter]
It's heads! You lose.
Wins: 1 | Losses: 1
Do you want to play again? (yes/no): no [Enter]
Thanks for playing! Final score: Wins: 1 | Losses: 1