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.
- 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
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
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
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.
- 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.