Step 7: Define play_round function

This functions stimulates one round of the game and displays the result.

  1. Takes an argument called word.
  2. Initialise guesses to 1
  3. Repeatedly ask the player for a guess by calling the function that gets player’s guess.
  4. Compare the guess to the target word by comparing letter by letter.
  5. 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
  6. Stop if the user guesses the word correctly or after 6 guesses
  7. Return a tuple where:
    • first argument is the number of guesses used
    • second argument is True if the word was guessed, otherwise False
πŸ’‘ Hint
  • You need a loop to allow the player up to 6 guesses and track the number of guesses used.
  • Use another loop to access each position in the word with range(…) and display the result.
ℹ️
  • Build your letter display string one character at a time.
  • You may find it helpful to start with an empty display string such as display = "".
⭐
display = ""
for i in range(len(word)):
    if guess[i] == word[i]:
        display += guess[i].upper() + " "
  • After displaying, check if the guess matches the word (make sure letter case is consistent when comparing) or if the number of guesses has reached the maximum 6 to return the tuple with the correct arguments
  • Otherwise, increment guesses and loop again.
βœ… Code Runner

Define play_round function

Type or paste your code and run.