πŸ“Œ Step 7: Define play_round function

This functions stimulates one round of the game.

  1. Takes an argument called word.
  2. Initialise guesses to 1
  3. Create an initial game_state tuple of five underscores.
  4. Repeatedly ask the player for a guess by calling the function that gets player guess.
  5. Compare the guess to the target word.
    • Do this by comparing each letter.
  6. 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
  7. Stop if the user guesses the word correctly or after 6 guesses
  8. Return a tuple where:
    • first argument is the number of guesses used
    • second argument is True is the word was guesses, otherwise False
πŸ’‘ 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.
⭐
display = ""
for i in range(len(word)):
    if guess[i] == word[i]:
        display += guess[i].upper() + " "
βœ… Checker

Define play_round function

Type or paste your code and run.