Learn to code a game to guess a number from your Pico.
Learn to create a random number generator and learn to make comparisons after receiving an input. This project will teach the the basics of computational thinking and coding logic.
Students will use loops, variables, and conditionals to create a game that will let them guess which number their Pico has generated.
Students will understand how to use comparisons in code to determine whether a value is greater than, less than, or equal to another.
Students will be able to determine if a device uses conditionals by learning about them in this activity.
I WILL BE ABLE TO...
Write mathematical functions (like greater than, less than, or equal to) in code
Use loops, variables, and conditionals to create a game that will let you guess a randomly-generated lock combination
Learning Activities
ELA Extension: Number Sleuth Mystery Writing
Pair students up or allow them to work independently based on writing level and creativity. Students will write a short mystery story or dramatic dialogue using clue-based logic, descriptive language, and critical thinking to narrow down a hidden number.
Begin by having students create a character—such as a robot detective (e.g., Pip, Piperbot) or a student sleuth—who is trying to solve a number mystery.
Next, students will generate 3–5 clues that logically describe the number. Examples: “It’s greater than 20 but less than 50.” “It’s even.” “It ends in 6.”
Students then write a story or skit in past tense, using vivid details and suspense. Encourage internal thoughts or dialogue like: “Could it be 46? No, that’s too high!” Stories should include a setting, character motivation, and what happens if they guess wrong.
Once finished, partners exchange stories and try to solve each other’s mystery before the ending is revealed.
Bonus vocabulary words to include: greater than, less than, equal to, range, clue, guess, logic
EXTENSION: Students create interactive mystery cards with clues for peers to solve in a gallery walk or guessing station.
ELD Extension: Secret Number Guessing Game
Pair students so that each English Learner (EL) is working with a fluent English speaker or a higher-level EL. Begin by reviewing key comparison terms: greater than, less than, equal to, between, before, after. Support comprehension with number lines, charts, or flashcards.
In pairs, students take turns thinking of a secret number within a chosen range (e.g., 1–50). The other partner guesses the number by asking yes/no questions:
“Is it greater than 20?”
“Is it even?”
“Is it less than 30?”
Students respond and track the clues to narrow down the range.
Support oral language development with sentence frames such as:
“I think your number is ___ because ___.”
“Your number is between ___ and ___.”
“It can’t be ___ because you said ___.”
After several rounds, students write a short journal entry about their best strategy or a clue they found confusing.
OPTIONAL CLASS GAME:
Play a whole-class version where the teacher picks a number and students take turns asking yes/no questions aloud using academic vocabulary.
Math Extension: Guess My Number – Logic & Range
Pair students or assign small groups based on grade level and readiness.
Begin by choosing a number range appropriate for your class (e.g., 1–20 for early grades, 1–100 for older students). Provide number lines or charts to help students visually eliminate guesses.
Each pair will take turns thinking of a secret number while the other asks yes/no questions to narrow the range. Students must use logic and eliminate options with each response.
Students will also track their thinking using a data table that shows:
Each guess
Clue received
Updated narrowed range
Once the number is guessed, students reflect and discuss:
“What was your best strategy?”
“How many guesses did it take?”
“Could you do it faster next time? Why or why not?”
EXTENSION CHALLENGE: Introduce the concept of binary search.
Ask students:
“What’s the fewest number of guesses possible if you always split the range in half?”
Have them compare binary search to random guessing and explain which is more efficient and why.
Have an different version? Look for more information on the Support Page.
Troubleshooting Tips
Are the number comparisons incorrect? Is your program saying 2 is greater than 5?
Ensure the directionality of your greater than (>) or lesser than (<) signs are arranged correctly.
What does Pico Guess indicate?
Pico Guess is a variable that stores a randomly generated number as coded for in the first line. When you click START, a new number is generated and stored in the variable.
Our customer support specialists are on hand to ensure your implementation of Piper runs seamlessly. View Support Docs or Contact Support
EXPANDED RESOURCES
Term Glossary
Circuit A conductive path for the flow of current or electricity.
Power The current or flow of electric charge and voltage.
Microcontroller An integrated circuit containing a microprocessor with memory and associated circuits.
Variables A value that can change depending on conditions or information passed to the program. A storage location with a symbolic name used to keep track of a value that can change while a program is running (similar concept to using X and Y in an algebraic equation). Variables are not only numbers; they can also hold text, including whole sentences (strings) or logical values (true or false).
Input Device A hardware device that sends data to a computer, allowing interaction and control.
Output Device A piece of hardware that converts information into a form humans can sense and understand.