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. Repeatedly ask the player for a guess by calling the function that gets player’s guess.
  4. Compare the guess to the target word.
    • Do this by comparing each 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 range(…) to loop through each position in the word. At each position, compare the guessed letter to the word’s letter at the same position, and check if the guessed letter appears anywhere in the word.
ℹ️
  • Build a 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() + " "
  • 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.