Does it live in other places besides Africa (not counting zoos?)- Yes. Partly brown?”) So different people might ask: Instead we can ask, “Is it brown?” (or “Can it be brown?” or “Is it Want to know what color it is, we may not ask “what color is it?” Remember that the Question Game requires yes or no answers. its abilities and usual activities, etc. what it looks like (size, color, wings or scales or fur, etc.), where the animal usually lives (continent, habitat, etc.), Players ask questions about various categories toĮliminate some possibilities. Means some kind of living creature, not meat or things made from The thinker says “I’m thinking of an animal.” (“ An animal” Before trying to guess the exactĪnswer, players ask questions to “narrow down” the possibilities.Ĭhallenge is that the “thinker” must answer truthfully, but will onlyĪnswer “yes” or “no” (or “sometimes.” He or she mayĪlso give hints, if necessary.) Here’s an Example: Then other players ask questions to see who can be first to guess Then tells the other players the category they will guess from.įriend- anything or anyone known to all the players.Ĭhoose something some players might not know!) Of something (or someone) that (or who, if a person) is.” To run the game, type this in your terminal python game.py and hit Enter.One person (the “thinker”) starts the game by saying, “I’m thinking Print('okay! '+ player_name+ ' I am Guessing a number between 1 and 10:') Player_name = input("Hello, What's your name?") If you have been following us, then this is how your program should look like: import random If the player couldn’t guess the number at the end we will print the number along with a message. if they did, then we will print a message for them along with the number of tries. Here we are first verifying if the user has guessed the number or not. Print('You did not guess the number, The number was ' + str(number)) Print('You guessed the number in ' + str(number_of_guesses) + ' tries!') The final if statement has the break keyword, which will terminate the loop entirely, So when the guess is equal to the generated number loop gets terminated.īelow the while loop, we need to add another pair of condition statements, if guess = number:.Similarly, we are checking if the guess is greater than the generated number.In the first, if statement we are comparing if the guess is less than the generated number if this statement evaluates to true, we print the corresponding Guess.In the next line, we are incrementing the value of number_of_guesses variable by 1.īelow it, we have 3 conditional statements. However, the user input we are getting from the user is a string object and to perform mathematical operations on it we first need to convert it to an integer which can be done by the Python’s inbuilt int() method. Within the loop, we are taking the input from the user and storing it in the guess variable. Our game will give user 5 attempts to guess the number, hence less than 5 because we have already assigned the number_of_guesses variable to 0. In the first line, we are defining the controlling expression of the while loop.
print('okay! '+ player_name+ ' I am Guessing a number between 1 and 10:') Later we will increase this value on each iteration of the while loop.įinally, before constructing the while loop, we will print a string which includes the player name. In the next step, we will create a variable named number_of_guesses and assign 0 to it.
player_name = input("Hello, What's your name?") Now we will prompt the user to enter his name and store it to a variable named player_name. Next, we will use the random module to generate a number between 1 to 10 and store it in a variable named number. To generate a random number we will use a Python module named random to use this module in our program, we first need to import it. Now, open your favorite text editor and start coding.įirst, we will create a file a new file named game.py from our text editor. In this article, we will guide you through each step of making this interactive guessing game in Python. Okay! Abhijeet I am Guessing a number between 1 and 10: This is how the game looks in action, Hello, What's your name? When the user guess matches the number computer will print the answer along with the number of attempts. This is going to be a simple guessing game where the computer will generate a random number between 1 to 10, and the user has to guess it in 5 attempts.īased on the user’s guess computer will give various hints if the number is high or low. Today we are going to make an interactive guessing game in Python.