GUESS MY NUMBER

PIPER MAKE EDUCATOR RESOURCES SERIES

To do this project, you will need a Piper Make Starter Kit. Get yours here:

Code your own guessing game to figure out what number your Pico is thinking of!

To get started, head to Piper Make and hit this icon:

Time: 30 minutes

Age Range: 8+

Difficulty: Beginner

Students will use loops and variables to create a guessing game. This project emphasizes programming skills. No wiring is required in this project.

Note: There are step by step instructions for the students to follow in the tutorials included in each project on Piper Make. These provide directions both for writing code and for building the electronic circuits. The tutorials are well-defined and most students will be able to follow them with little assistance required.

LEARNING OBJECTIVES

Students will:

 

  • Create programs that use variables to store and modify data.
  • Create programs that include events, loops, and conditionals.
  • Decompose problems into smaller, manageable tasks which may themselves be decomposed.
  • Create programs by incorporating smaller portions of existing programs, to develop something new or add more advanced features.
  • Test and debug a program or algorithm to ensure it accomplishes the intended task.

STANDARDS ALIGNMENT

CA Computer Science Standards

3-5.AP.11: Create programs that use variables to store and modify data.

3-5.AP.12: Create programs that include events, loops, and conditionals.

3-5.AP.13: Decompose problems into smaller, manageable tasks which may themselves be decomposed.

3-5.AP.14: Create programs by incorporating smaller portions of existing programs, to develop something new or add more advanced features.

3-5.AP.17: Test and debug a program or algorithm to ensure it accomplishes the intended task.

Math Content Standards Alignment

CCSS.MATH.CONTENT.4.NBT.A.2: Read and write multi-digit whole numbers using base-ten numerals, number names, and expanded form. Compare two multi-digit numbers based on meanings of the digits in each place, using >, =, and < symbols to record the results of comparisons.

LANGUAGE OBJECTIVES

CCSS.ELA.L.W.3.8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

CCSS.ELA.L.W.3.10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

CA ELD.3.C.11: Supporting own opinions and evaluating others’ opinions in speaking and writing

CA ELD.3.C.12: Selecting and applying varied and precise vocabulary and language structures to effectively convey ideas

MICHIGAN INTEGRATED TECHNOLOGY COMPETENCIES FOR STUDENTS (MITECS)

1B-AP-09 Create programs that use variables to store and modify data. Subconcept: Variables; Practice 5.2

1B-AP-10 Create programs that include sequences, events, loops, and conditionals. Subconcept: Control; Practice 5.2

1B-AP-11 Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process. Subconcept: Modularity; Practice 3.2

1B-AP-12 Modify, remix, or incorporate portions of an existing program into one’s own work, to

develop something new or add more advanced features. Subconcept: Modularity; Practice 5.3

1B-AP-15 Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended. Subconcept: Program Development; Practice 6.1, 6.2

 

Core Content Standards

 

Michigan Math Standards

1.NBT.3: Compare two two-digit numbers based on meanings of the tens and ones digits, recording the results of comparisons with the symbols >, =, and <.

2.NBT.4: Compare two three-digit numbers based on meanings of the hundreds, tens, and ones digits, using >, =, and < symbols to record the results of comparisons.

4.NBT.2: Read and write multi-digit whole numbers using base-ten numerals, number names, and expanded form. Compare two multi-digit numbers based on meanings of the digits in each place, using >, =, and < symbols to record the results of comparisons.

 

Language Objectives

 

Michigan ELA, Grade 3-8, Research, 8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

Michigan ELA, Grade 3-8, Range of Writing, 10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

 

WIDA ELD Standards

ELD-SI.K-3.Argue:

  • Ask questions about others’ opinions
  • Support own opinions with reasons
  • Clarify and elaborate ideas based on feedback
  • Defend change in one’s own thinking
  • Revise one’s own opinions based on new information

 

ELD-SC.2-3.Argue.Interpretive:

Interpret scientific arguments by

  • Identifying potential evidence from data, models, and/or information from investigations of phenomena or design solutions
  • Analyzing whether evidence is relevant or not
  • Distinguishing between evidence and opinions

CONCEPTS

Students will use conditionals (“if”, “else if”) and loops to program the Pico to guess a random number. Code using inequalities (“<”, “>”) will help the student guess the number.

PARTS

Raspberry Pi Pico, breadboard, charging cable

GPIO SETUP

none

OVERVIEW OF STEPS

Step 1: Remember this game?

Piperbot has a number between 1 and 20 hidden, and Pip is trying to guess what it is!

You probably played this game when you were younger. But you know what? It's just as much fun to play now, especially when you build it yourself!

This time, you will be guessing a number that the Pico is hiding from you!

Are you ready to get started? Click NEXT.

Step 2: Get your stuff

The only thing you need for this tutorial is your Pico module. Once you have it ready, click NEXT.

Step 3: Get a random number

The first thing the Pico needs to do is come up with its own random number.

Since we will need to use it several times in our program, we will store it in a variable.

Start by dragging out a start block from the Chip menu. Then, in the Variable menu, click the Create variable button and name our new variable "pico guess".

Then, drag out the set pico guess to block and connect it to the start block.

Finally, in the Values menu, find the random integer from block and place it in the set pico guess to block.

Click NEXT.

Step 4: Get the player's guess

Now that the Pico has secretly guessed a number, we need to let the player try to guess what that number is.

Since we stored the Pico's guess in a variable, we need to do the same for the player's guess.

Open the Variables menu, and click the Create Variable button again. Name the new variable "player guess".

Then, drag the set player guess to block and connect it to the bottom of your program:

Wait a minute! Will guessing a number from 1 to 100 be too difficult? Change the second number to 20, then click NEXT.

Step 5: Variable types

We will play this game using the CONSOLE tab at the bottom of the workspace. Remember using a print block to send information to the console?

This time, we are going to use an ask block from the Chip menu to send information to the Pico. The ask block returns the text that the user types into the CONSOLE.

But wait! When you type into the console, it sends text characters back to the Pico. The problem is that a text value and a number value are not the same!

For example, "24" is a "2" character and a "4" character, and that's different than the number 24. The good news is that we can convert "24" to 24 using a number from text block in the Values menu.

Drag a number from text block into the set player guess to block:

Click NEXT.

Step 6: Ask the player

Now we are ready to get the player's guess! Drag an ask block from the Chip menu and place it into the number from text block.

Why does the ask block have a "_" that you can type into? That's where you type in a question to ask!

Type "Guess a number from 1 to 20":

Then, click NEXT.

Step 7: Was their guess...

Now we have both the Pico's guess and the player's guess, so we need to compare them and then tell our player if their guess was:

too high,
too low,
or if they guessed correctly

That means we need an if block! Grab the if block from the Logic menu that already has an _ = _ block in it, and connect it to your code:


Think about what will happen if the Pico's guess is 10 and the player guesses 8. How will we know? The player's guess will be less than the Pico's guess, right? What if the player guesses 12? Then their guess would be greater than the Pico's.

If their guess isn't too high, and it's not too low, then it must be correct! This sounds like a job for an if else-if else block!

Click the blue gear icon on the if block. In the menu that pops up, drag over 1 else if block, and then drag over 1 else block:

Click the blue gear icon to close the menu, then click NEXT.

Step 8: Make the comparisons

Now we need to compare the player's guess to the Pico's guess.

Drag a player guess block from the Variables menu to the left side of the _ = _ block. Then, drag a pico guess block from the Variables menu to the right side of that block. Finally, change the = to a < (less than).

Duplicate the _ < _ block and drag it into the else if condition. Change the < (less than) to > (greater than):

Click NEXT.

 

Step 9: Give our player a hint

Now we need to tell the player how they are doing. Did they guess to low? Tell them using a print block!

Let's make print blocks that say "Too low", "Too high", and "You won!". You can find the print block in the Chip menu. Where should those blocks go in our if else-if else statement?

Did you get the print blocks added in? If so, click NEXT.

Step 10: Try it out

Let's try out our game! Do you think it will work?

Since this game is played using the CONSOLE, click the CONSOLE tab at the bottom of the workspace to open it up.

Next, click CONNECT, then click START.

You should see this in the CONSOLE:

Before you can type in the CONSOLE, you have to click it. When you do, the cursor will start blinking, which means that it is ready for you to type in a number!

Try it out! Type a number between 1 and 20, and then press Enter or Return on your keyboard.

Click NEXT.

Step 11: Did it work?

Did it work? Did your game tell you if your guess was too high or too low? Were you lucky enough to win?

Any of the above could have happened, but after one guess, your program stopped! Why?

Click NEXT to find out how we can make it better!

Step 12: Guess again!

If we want to keep guessing, our game needs to loop back to the point in our program where it asks for and stores the player's guess in a variable.

Grab the set player guess to block in your program and pull it away from the set pico guess to block.

Then, drag out a repeat forever block from the Loops menu and connect it to the set pico guess to block. Finally, put all of the blocks inside of the repeat forever block:

Click NEXT.

Step 13: The never ending game

Click START to play your game. Click NEXT when you win!

Step 14: Break the loop!

Did your game ask you to guess again even after you won? How can we fix that?

After we win, we need to exit out of the loop. We can do this by adding an exit block from the Loops menu right after the print "You won!" block:

Try your game again by clicking START. After you win, click NEXT.

Step 15: Congratulations!

You just built a really cool game! What are some ways to change it up? Could you make it harder? Could you make this a two-player game? Experiment and have some fun with it!

When you're ready to try some new tutorials or projects, click EXIT to go back to the start screen.