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

CSTA's K-12 Standards 

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

CCSS Math

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.

CCSS ELA

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.

World-Class Instructional Design and Assessment (WIDA) English Language Proficiency StandardsMt

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

California's K-12 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

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.

Common Core English Language Arts

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.

California English Language Development Standards

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

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.

Michigan English Language Arts

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 English Language Development

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

Science Texas Essential Knowledge & Skills Grade 3

(b)(2) Scientific investigation and reasoning. The student uses scientific practices during laboratory and outdoor investigations. The student is expected to:
(A) plan and implement descriptive investigations, including asking and answering questions, making inferences, and selecting and using equipment or technology needed, to solve a specific problem in the natural world;

(b)(3) Scientific investigation and reasoning. The student knows that information, critical thinking, scientific problem solving, and the contributions of scientists are used in making decisions.

Science Texas Essential Knowledge & Skills Grade 4

(a)(1)(A) Within the physical environment, students know about the physical properties of matter including mass, volume, states of matter, temperature, magnetism, and the ability to sink or float. Students will differentiate among forms of energy including mechanical, light, sound, and thermal energy. Students will explore electrical circuits and design descriptive investigations to explore the effect of force on objects.

(b)(3) Scientific investigation and reasoning. The student uses critical thinking and scientific problem solving to make informed decisions. The student is expected to:

    (A) analyze, evaluate, and critique scientific explanations by using evidence, logical reasoning, and experimental and observational testing;

    (B) represent the natural world using models such as the water cycle and stream tables and identify their limitations, including accuracy and size; and

    (C) connect grade-level appropriate science concepts with the history of science, science careers, and contributions of scientists.

Science Texas Essential Knowledge & Skills Grade 5

(a)(1) In Grade 5, scientific investigations are used to learn about the natural world. Students should understand that certain types of questions can be answered by investigations and that methods, models, and conclusions built from these investigations change as new observations are made. Models of objects and events are tools for understanding the natural world and can show how systems work. They have limitations and based on new discoveries are constantly being modified to more closely reflect the natural world.

(a)(3) Recurring themes are pervasive in sciences, mathematics, and technology. These ideas transcend disciplinary boundaries and include patterns, cycles, systems, models, and change and constancy.

Math Texas Essential Knowledge & Skills Grade 3

(b)(2) Number and operations. The student applies mathematical process standards to represent and compare whole numbers and understand relationships related to place value. The student is expected to:

(D) compare and order whole numbers up to 100,000 and represent comparisons using the symbols >, <, or =.

Math Texas Essential Knowledge & Skills Grades 6-8

(b) Knowledge and skills.

  (1) Mathematical process standards. The student uses mathematical processes to acquire and demonstrate mathematical understanding. The student is expected to:

    (A) apply mathematics to problems arising in everyday life, society, and the workplace;

    (B) use a problem-solving model that incorporates analyzing given information, formulating a plan or strategy, determining a solution, justifying the solution, and evaluating the problem-solving process and the reasonableness of the solution;

    (C) select tools, including real objects, manipulatives, paper and pencil, and technology as appropriate, and techniques, including mental math, estimation, and number sense as appropriate, to solve problems;

    (D) communicate mathematical ideas, reasoning, and their implications using multiple representations, including symbols, diagrams, graphs, and language as appropriate;

    (E) create and use representations to organize, record, and communicate mathematical ideas;

    (F) analyze mathematical relationships to connect and communicate mathematical ideas; and

    (G) display, explain, and justify mathematical ideas and arguments using precise mathematical language in written or oral communication.

 

(2)Number and operations. The student applies mathematical process standards to represent and use rational numbers in a variety of forms. The student is expected to:

(C) locate, compare, and order integers and rational numbers using a number line;

ELA Texas Essential Knowledge & Skills Grade 3

(b) (1)Developing and sustaining foundational language skills: listening, speaking, discussion, and thinking--oral language. The student develops oral language through listening, speaking, and discussion. The student is expected to:

    (A) listen actively, ask relevant questions to clarify information, and make pertinent comments;

    (B) follow, restate, and give oral instructions that involve a series of related sequences of action;

    (C) speak coherently about the topic under discussion, employing eye contact, speaking rate, volume, enunciation, and the conventions of language to communicate ideas effectively;

    (D) work collaboratively with others by following agreed-upon rules, norms, and protocols; and

    (E) develop social communication such as conversing politely in all situations.

ELA Texas Essential Knowledge & Skills Grades 4 & 5

(b) (1)Developing and sustaining foundational language skills: listening, speaking, discussion, and thinking--oral language. The student develops oral language through listening, speaking, and discussion. The student is expected to:

    (A) listen actively, ask relevant questions to clarify information, and make pertinent comments;

    (B) follow, restate, and give oral instructions that involve a series of related sequences of action;

    (C) express an opinion supported by accurate information, employing eye contact, speaking rate, volume, enunciation, and the conventions of language to communicate ideas effectively; and

    (D) work collaboratively with others to develop a plan of shared responsibilities.

(b)(13) Inquiry and research: listening, speaking, reading, writing, and thinking using multiple texts. The student engages in both short-term and sustained recursive inquiry processes for a variety of purposes. The student is expected to:

    (A) generate and clarify questions on a topic for formal and informal inquiry;

    (B) develop and follow a research plan with adult assistance;

    (C) identify and gather relevant information from a variety of sources;

    (D) understand credibility of primary and secondary sources;

    (E) demonstrate understanding of information gathered;

    (F) differentiate between paraphrasing and plagiarism when using source materials;

    (G) develop a bibliography; and

    (H) use an appropriate mode of delivery, whether written, oral, or multimodal, to present results.

§74.4. English Language Proficiency Standards

(c) Cross-curricular second language acquisition essential knowledge and skills.

(3) Cross-curricular second language acquisition/speaking.

(D) speak using grade-level content area vocabulary in context to internalize new English words and build academic language proficiency;

(E) share information in cooperative learning interactions;

(F) ask and give information ranging from using a very limited bank of high-frequency, high-need, concrete vocabulary, including key words and expressions needed for basic communication in academic and social contexts, to using abstract and content-based vocabulary during extended speaking assignments;

(G) express opinions, ideas, and feelings ranging from communicating single words and short phrases to participating in extended discussions on a variety of social and grade-appropriate academic topics;

(H) narrate, describe, and explain with increasing specificity and detail as more English is acquired;

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.

Guess My Number

Step 2: Get your stuff

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

Guess My Number

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.

Guess My Number

Step 4: Get the player's guess

Guess My Number

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

Guess My Number

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.

Guess My Number

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.

Guess My Number
Guess My Number

Step 8: Make the comparisons

Guess My Number

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.

Guess My Number

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.

Guess My Number

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.

Guess My Number

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.

Guess My Number

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.