We want to take it a step further to keep track of two things:
The letters that the user has correctly chosen - and their position in the word.
The number of guesses the user has made
To implement (1), we'll use a 'Dictionary'. This dictionary tells us which letter has been correctly guessed and which letter has not.
Use an integer variable to store (2).
Notes:
Create a dictionary using each letter in the target word as a key.
Let the values of each key be 'false' by default. eg
Note that 'C' isn't repeated because keys in a dictionary should be unique. This also suits our usage because once you guess a letter, it covers all occurrences of the letter.
If a letter is guessed correct, the dictionary is set to 'true'
Print out the dictionary when the user quits the application.
We want to take it a step further to keep track of two things:
To implement (1), we'll use a 'Dictionary'. This dictionary tells us which letter has been correctly guessed and which letter has not. Use an integer variable to store (2).
Notes:
Note that 'C' isn't repeated because keys in a dictionary should be unique. This also suits our usage because once you guess a letter, it covers all occurrences of the letter.