π Step 7: Define play_round function
This functions stimulates one round of the game.
- Takes an argument called
word. - Initialise
guessesto 1 - Create an initial
game_statetuple of five underscores. - Repeatedly ask the player for a guess by calling the function that gets player guess.
- Compare the guess to the target
word.- Do this by comparing each letter.
- Display each letter as:
- uppercase if in correct position
- lowercase if it is in the word but wrong position
- as an underscore if not in the word
- Stop if the user guesses the word correctly or after 6 guesses
- Return a tuple where:
- first argument is the number of guesses used
- second argument is
Trueis the word was guesses, otherwiseFalse
π‘ Hint
- You need a loop to allow the player up to 6 guesses.
- Start by setting
guesses = 1. - You can call
get_player_guess()inside the loop to get each guess. - Use
range(len(word))to loop through each position in the word.
βΉοΈ
- If
guess[i] == word[i], the letter is correct and in the correct position. - If
guess[i] in word, the letter is in the word but in the wrong position. - Otherwise, display
_.
βΉοΈ
- Build the display string one character at a time.
- You may find it helpful to start with an empty display string such as
display = "". - Add a space after each symbol to match the required output format.
β Checker
Define play_round function
Type or paste your code and run.