In 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:
We will then use this function in our game:
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.