Computer Science
Grade 2
20 min
Making a Peanut Butter Sandwich Algorithm
Students create an algorithm for making a peanut butter sandwich.
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Define an algorithm as a set of steps.
Explain why the sequence (order) of steps is important.
Write a simple, step-by-step algorithm for a familiar task.
Identify a 'bug' or mistake in a simple algorithm.
Give clear and specific instructions for a computer (or robot friend).
Correct a bug by changing the sequence of instructions.
Have you ever told a robot what to do? 🤖 Let's teach one to make a sandwich! 🥪
We will learn how to give instructions to a computer. This is called an algorithm! The order of our steps is very important.
Real-World Applications
Following a recipe to bake cookies 🍪
Building a LEGO set using the instructions 🧱
Getting ready for school in the morning ☀️
Playing a board game by following the rules 🎲
2
Key Concepts & Vocabulary
TermDefinitionExample
AlgorithmA list of steps to finish a task. It's like a recipe! 📜The steps to brush your teeth is an algorithm.
SequenceThe order that you do the steps in. First, then next, then last. ➡️First, you get the bread. Next, you get the peanut butter.
InstructionOne single step in your algorithm. It tells the computer what to do. 🗣️A single instruction is: 'Open the peanut butter jar.'
ProgramAll the instructions put together for the computer to follow. 💻Your whole peanut butter sandwich recipe is a program.
BugA mistake in your algorithm that stops it from working. Oops! 🐞A bug is telling the robot to spread peanut butter on the table.
DebuggingFinding and fixing the bugs in your algorithm. Let's fix it! 🛠️You see the robot making a mess. You debug b...
3
Core Syntax & Patterns
Rule 1: Order Matters! 順番
Instructions must be in the correct sequence.
You must do things in the right order, or it won't work. You can't put the roof on a house before the walls!
Rule 2: Be Super Specific! 具体的
Instructions must be very clear and small.
Computers don't have brains like us. You can't just say 'make a sandwich'. You have to tell them every tiny step.
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
Your perfect peanut butter sandwich algorithm is 10 steps long. To change it to a jelly sandwich algorithm, what is the MINIMUM number of steps you must change?
A.All 10 steps
B.Two steps: 'Get peanut butter jar' and 'Open peanut butter jar'
C.Only one step: 'Spread peanut butter'
D.Five steps
Challenging
A robot must make a sandwich for a friend, but you don't know if they have a peanut allergy. What is the most important 'IF' question the robot should ask at the start of its algorithm?
A.IF you are hungry, THEN I will make a sandwich.
B.IF the bread is fresh, THEN continue.
C.IF it is lunchtime, THEN start.
D.IF you have a peanut allergy, THEN stop and use something else.
Challenging
An algorithm for a factory robot makes 100 sandwiches an hour. Which is a more important goal for this algorithm?
A.To be as fast and efficient as possible, with no wasted moves
B.To have instructions that are easy for a person to read
C.To use the most expensive peanut butter
D.To make each sandwich look unique
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing Free