Step 7: Define play_round function
While Loops π
For Loops π
String Indexing π
String Methods π
If Statements π
Membership Operators π
Comparison Operators π
Tuples π
This functions stimulates one round of the game and displays the result.
- Takes an argument called
word. - Initialise
guessesto 1 - Repeatedly ask the player for a guess by calling the function that gets playerβs guess.
- Compare the guess to the target
wordby comparing letter by 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
Trueif the word was guessed, otherwiseFalse
π‘ 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.
- 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
guessesand loop again.
β Code Runner
Define play_round function
Type or paste your code and run.