concept guess in category python

This is an excerpt from Manning's book Get Programming: Learn to code with Python.
secret = "snake" word = input("What's my secret word? ") guesses = 1 while word != secret: word = input("What's my secret word? ") if guesses == 20 and word != secret: print("You did not get it.") break guesses += 1
Start with a guessing game. You think of a secret word and ask a player to guess your word. Every time the player makes a guess, tell them whether they’re right. If they’re wrong, ask again. Keep track of the number of guesses a player makes until they get it right. Figure 18.1 shows a flowchart of this game.
Figure 18.1. Flowchart of the guessing game. A user guesses a word. The guessing loop is represented by the gray diamond, which checks whether the user guess is equal to the secret word. If it is, the game finishes. If it isn’t equal, you tell the player that they’re wrong, ask them to guess again, and add 1 to the number of times that they made a guess.
![]()
Listing 18.1 shows an implementation of the game in code. The user is trying to guess a secret word chosen by the programmer. The user is first prompted to enter a word. The first time you reach the while loop, you compare the user guess with the secret word. If the guess isn’t correct, you enter the while loop code block, consisting of three lines. You first print the number of times the user guessed so far. Then you ask the user for another guess; notice that the user’s guess is assigned to the variable guess, which is used in the while loop’s condition to check the guess against the secret word. Lastly, you increment the number of tries to keep an accurate count of the number of times the user tried to guess the word.