Heads or Tails

flip-a-coinIn this challenge we will create a game of heads to tails using the following rules:

  • The game will consist of 5 rounds.
  • In each round:
    • the user will make a guess,
    • the computer will flip a coin,
    • the player will score 1 point for a correct guess.

In order to complete this game we will first create a function called flipCoin() to flip a coin and return the value “Heads” or “Tails”.

Here is the flowchart for this function:
flipcoin-function-flowchart

We will then use this function in our game:
heads-or-tails-flowchart

From flowchart to Python code


Using both flowcharts provided above, you can now implement the full code for this game:

Extension Task #1


Can you tweak this code so that the user can only enter the value “Heads” or “Tails” and nothing else. (If they do, the program should ask them to re-enter their guess until they enter a valid guess.)

Extension Task #2


Add some code so that when the 5 rounds are over, the user is given the option to either start a new game or to quit.
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 3.8 / 5. Vote count: 19

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: