Guess my number


Guess my number - CS Unplugged

This is similar to the game of 20 questions, but it is about guessing a number with the strict rule that you can only answer whether the secret number is greater than or equal to a guessed number.

What you need

  • At least 2 people
  • A pen or pencil
  • Two or three pieces of paper

Skills needed

  • Comparing numbers up to 100

Key question

How quickly can you find an answer just by asking questions that have a yes or no answer?

Activity steps

I’ve written a secret number on this paper, and you need to work out what it is. It’s between 1 and 100. Each time you tell me a number, I’ll tell you if my number is greater than or equal to your one. I won’t tell you if it’s equal - but you’ll still be able to work out my number!

Write a number on some paper, and fold it over so it can’t be seen. It can be any number from 1 to 100; in the example below the parent happens to have chosen 52 as the secret number.

What number do you want to guess first?

Write a "greater than or equals" symbol followed by their guess. (In the example, the child has guessed 50.)

(Depending on the number)
My secret number is not greater than or equal to your guess.
or
My secret number is greater than or equal to your guess.

Write a tick or cross depending on whether it is greater than or equal. Since 52 (the secret number) is greater than or equal to the guess (50), the presenter has written a cross.
Do not tell them if they have guessed your number! They will need to work out when they have enough information to know the number, so this is different to traditional versions of games like "20 guesses". The best guessing strategy is to start by guessing 50 (which the child happened to do in this case), but it’s fine if the child wants to use another approach - let them work it out for themselves!

Which number do you want to guess next? Again, say one of these:
My secret number is not greater than or equal to your guess.
or
My secret number is greater than or equal to your guess.

In this case the child has guessed 75. The secret number isn’t greater than equal to 75, so the presenter has marked it with a cross.

This repeats until the child can guess the number.

In the example, the child happens to have named the secret number (52), but the presenter has only said that their guess is greater than or equal to the secret number.

As it happens, the child can deduce that the number must be 52 from the information available, since they found out earlier that it’s not greater than or equal to 53. It can take a bit of logic to work this out, but it’s always possible to narrow in on the number.

You can play this game a few times so that they can refine their strategy and develop their logical thinking to find the answer. After a while they may discover that it’s strategic to keep dividing the range in half.

Inside the computer

This activity touches on several key ideas in computing. One is that dividing big problems in half, then half again, and so on, makes them very small very quickly. With 100 possible values, only 7 questions are ever needed to narrow down to the secret value if you use the right strategy. In Arnold’s challenges students can experiment with guessing numbers from 1 to 1000 - it looks like it would be 10 times as hard, but it only needs three more questions! Every time the range doubles in size, you only need one more question to guess a number in the range. In fact, you could guess a number from 1 to a million using only 20 questions - it doesn’t take that long, although you might want to use a calculator to half the range each time. This approach to narrowing down towards a solution is behind some very fast computer algorithms.

Another idea in the activity is that you can achieve a lot with only "binary" yes/no decisions. You might think that you need to check if the final value is equal, but you can know for use only by using "greater than or equal". Decisions that have two outcomes (often referred to as true or false) are the basis of "Boolean logic", which is one of the key ideas used in the design of digital devices.

Arnold's challenges

Click here to view Arnold's challenges:

Arnold's Challenges

Guess My Number 3-5 | Math Solutions

Download or Print this Lesson

A Lesson with Third, Fourth, and Fifth Graders

by Rusty Bresser and Caren Holtzman

Guess My Number invites children to consider the structure of the number system while engaging in a logic game. Students try to guess a secret number from within a given range of possibilities. Guess My Number also presents an opportunity to reinforce mathematical symbols such as the “greater than” and “less than” signs. Through this activity, students learn the usefulness of number lines as tools for solving problems. Guess My Number appears in Rusty Bresser and Caren Holtzman’s Minilessons for Math Practice, Grades 3–5 (Math Solutions Publications, 2006).

As Patty Stark’s fifth graders settled into their seats, I went to the board and drew a box with a question mark inside it.

“Good morning,” I greeted the class. “I’ve got a secret number for you to guess. Since it’s early in the morning I’m going to make it pretty easy for you. I’ll tell you the number is somewhere between one and one hundred.”

“Could it be one hundred?” Martina asked.

“Yes,” I responded. “It could be any number between one and one hundred, including one or one hundred. You can guess a number and I’ll tell you if my secret number is greater than or less than your guess.

I drew a number line on the board to help the students keep track of their guesses.

“How about fifty?” Latoya asked.

“The secret number is less than fifty,” I told her as I wrote this information on the board. I also marked 50 on the number line with an arrow, indicating all the numbers fifty and above were too large.

Before I took any more guesses I decided to have a brief discussion about strategies for guessing. I had deliberately picked an easy number to start with so we could focus on the mechanics and thinking involved with the game.

“I’m a bit curious, Latoya,” I said. “Is there a particular reason you chose fifty?”

“Yeah,” Latoya responded. “I knew your number was between one and one hundred, so I picked fifty because it’s in the middle.”

“So how does that guess help you?” I pushed.

“Because it splits the numbers. Since you said the secret number is less than fifty, I know it’s in the bottom half of the numbers.”

I summarized Latoya’s strategy with accompanying references to the number line. “I think I get it,” I told the class. “All the possible numbers are between one and one hundred. So if you guess a number right in the middle, you can figure out which half the secret number is in and then you can just throw away the other half and not have to worry about it.”

I proceeded to take some more guesses. Within a minute the number line looked like this:

I then asked students to pair up and briefly discuss two things—what they thought they already knew about my secret number and what number they’d like to guess next. I wrote the two prompts on the board to help them stay focused. Also, I was giving them a preview of the discussion to come.

What do you already know about my secret number?

What next guess would you like to make? Why?

After a few minutes I called for the students’ attention. “So can anyone tell something you know about my secret number?” I asked.

“It’s more than forty,” Hilario offered.

“It’s between forty and fifty,” David added.

“It’s in the forties,” Brenda posited.

“So you already know a lot about the secret number,” I validated. “With all this information, what number would you like to guess next? If you raise your hand to guess a number, you also have to be willing to explain why you think that number is a helpful guess.”

I called on Destinee. “Forty-five,” she volunteered.

“Why is forty-five helpful?” I asked.

“Because,” Destinee explained, “we know the secret number is in the forties, and forty-five is in the middle of the forties.”

“It’s just like Latoya’s idea,” Reynaldo chimed in. “You can get rid of half the numbers that are left.”

“Aha,” I responded, “so you’re using your logical thinking to help eliminate a bunch of possibilities with one guess. Well, I’ll tell you that the secret number is less than forty-five. Talk to a partner again about what you know about the number now and what guess you’d like to make next.”

I let the students talk to each other as I added the new information to the number line. Many students wanted to use the same strategy and pick the number that was halfway between 40 and 45. We took a brief detour to establish that 42.5 was the midpoint between 40 and 45, but I explained that this Guess My Number game involved whole numbers only, so they needed to choose either 42 or 43.

Christina guessed forty-two. I told her that the secret number was greater than forty-two and recorded this information on the board. Then Kenny guessed forty-nine. Some students expressed frustration with his guess since they already knew the number was less than forty-five. I stopped briefly to have a talk about maintaining a safe environment.

“This is a new game we’re playing today,” I told the class. “Part of learning and trying new things is making mistakes. It’s really important that everyone in the class feels safe enough to share his or her ideas and sometimes make mistakes. That’s how we learn. If you disagree with someone or you have a different idea, that’s fine. Just make sure you communicate that in a way that won’t hurt anyone’s feelings. Do you know what I’m talking about?” I asked the class as I looked at each student.

“Yes,” the students murmured.

I added Kenny’s guess to the board and moved on.

“How about forty-three?” Lisa suggested.

I wrote 43 on the board and circled it.

“Yes,” I congratulated. “My number is forty-three. I’m impressed with everyone’s thinking. It could have been any of one hundred different numbers, and it took you only eight guesses to get it. That shows you used a lot of good mathematical thinking.”

Before I left the class, I called on a pair of students to lead the class in another round of Guess My Number.

Guess My Number works equally well with fractions, decimals, or percents. Giving the students some visual tools is essential. Using a number line helps students compare numbers and order the numbers.

A 1–100 chart is another tool that works nicely for Guess My Number. Tell students that the secret number is somewhere on the 1–100 chart. Cross numbers off the chart as they are eliminated. Familiarity with a 1–100 chart gives upper-elementary students a distinctive edge when it comes to mental computation and understanding our number system. When students have a visual model of the chart in their heads, they can easily jump around using tens. They also have a useful geometric model (the 10-by-10 square) to get a feel for how numbers are related to one another. Playing Guess My Number with a 1–100 chart gives students further exposure to the chart and pushes them to articulate some of the number relationships inherent in it.


Featured in Math Solutions Online Newsletter, Spring 2007, Issue 25

Related Publication:
Minilessons for Math Practice, Grades 3-5
by Jennifer M. Bay-Williams and Sherri L. Martinie

Share:

Python script - guess the number game.

Django site creation example

In this free course, you will see an example of creating a full-fledged site in Django, which will give you a great start when creating your own sites on this framework.

To receive the Video course,
fill out the form

Email:
Name:

Other courses

5 steps and a professional website is ready

After the workshop:

- You will have a clear action plan.

- You will be able to start creating a website.

- You can easily navigate through the information on creating websites.

Sign up

Other courses

Life is like riding a bicycle. To keep your balance, you must move.

Albert Einstein

Python script - guess the number game.

# file guess_number.py
# import the module for working with random numbers
import random

# number of attempts to guess
guesses_made = 0

# get username from console input
name = input('Hi! What's your name?\n')

# get a random number between 1 and 30
number = random. randint(1, 30)
print ('Great, {0}, I guessed a number between 1 and 30. Can you guess?'.format(name))

# until the user has exceeded the number of attempts allowed - 6
while guesses_made < 6:

# get number from user
guess = int(input('Enter number: '))

# increase the counter of the number of attempts
guesses_made += 1

if guess < number:
print ('Your number is less than what I guessed.')

if guess > number:
print ('Your number is greater than what I guessed.')

if guess == number:
break

if guess == number:
print ('Wow, {0}! You guessed my number using {1} attempts!'.format(name, guesses_made))
else:
print ('But I didn't guess! I guessed the number {0}'.format(number))

We call like this:

C:/> python guess_number.py
  • Created on 04/30/2020 12:13:25 PM
  • Mikhail Rusakov

Previous articleNext article

Copying of materials is allowed only with the indication of the author (Mikhail Rusakov) and an indexed direct link to the site (http://myrusakov. ru)!

Add me as a friend VKontakte : http://vk.com/myrusakov.
If you want to evaluate me and my work, then write it in my group: http://vk.com/rusakovmy.

If you do not want to miss new materials on the site,
then you can subscribe to updates : Subscribe to updates

If you have any questions, or you have a desire to comment on this article, then you can leave your comment at the bottom of the page.

Recommend this article to your friends:

If you liked the site, then place a link to it (on your site, on the forum, in contact):

  1. Button:
    How to create your own website< /a>

    It looks like this:

  2. Text link:
    How to create your website

    It looks like this: How to create your own website

  3. BB-code of the link for forums (for example, you can put it in the signature):
    [URL="https://myrusakov. ru"]How to create your site[/URL]

Guess the number with Python! - pythobyte.com

Today I'll be sharing tips on how to make a Guess the Number game with the Python programming language.

Let's get started!

👉 Import the random module to randomly generate numbers in the game.

 import random 

💡 Enter an endless loop.

👉 Generate a random number, initialize the odds to zero.

 while True: print("\nN U M B E R G U E S S I N G G A M E") print("\nYou have 10 chances to guess the number. ") # randint function to generate the random number between 1 to 100 number = random randint(1, 100) """ number of chances to be given to the user to guess the number or it is the inputs given by user into input box here number of chances are 10 """ chances = 0 print("Guess a number (1 - 100):") 

👉 Add a Wime Loop to count the number of chances used and take input from the user.

 # While loop to count the number of chances while chances < 10: # Enter a number between 1 and 100 guess = int(input()) 

👉 Accordingly, the user with the guess number is entered.

 # Compare the user entered number with the number to be guessed if guess == number: """ if number entered by user is same as the generated number by randint function then break from loop using loop control statement "break" """ print("Congratulations YOU WON!!!") break # Check if the user entered number is smaller than the generated number elif guess  

👉 Increase the value of variable chances one at a time when the user will use one chance at a time.

 # Increase the value of chance by 1 as 1 chance is used chances += 1 

👉 Make sure the user defined the number or not.

 # Check whether the user guessed the correct number if not chances < 10: print("YOU LOSE!!! The number is", number) 

👉 Ask a replay question and break the endless loop.


Learn more