CS: Debugging: Finding and Fixing Errors
Practice spotting mistakes and improving simple programs
Practice spotting mistakes and improving simple programs
CS - Grade 4-5
- 1
A program is supposed to print Hello, Sam! The code says: print("Hello, Sam!". Find the error and write the corrected code.
- 2
A robot should move forward 3 spaces, turn right, and then move forward 2 spaces. The instructions are: move forward 3, turn left, move forward 2. Find the bug.
- 3
This program should count from 1 to 5, but it prints 1, 2, 3, 4. Code: for number in 1 to 4: print(number). What should be changed?
- 4
A game gives 10 points when a player catches a star. The code says: score = score - 10. Explain the bug and fix it.
- 5
A program checks if a student can enter a ride. The rule is: students must be 48 inches or taller. The code says: if height > 48 then enter. What is the problem?
- 6
Look at this algorithm for making a peanut butter sandwich: 1. Put peanut butter on bread. 2. Open the jar. 3. Get bread. 4. Eat sandwich. What sequencing bug do you see?
- 7
A drawing program should draw a square. The instructions are repeated 4 times: move forward 50, turn right 90. A student changes it to repeat 3 times. What will happen?
- 8
A program asks for a name and then says hello. Code: name = input("What is your name?") print("Hello, name"). What is the bug?
- 9
A student tests a calculator program with 2 + 3 and gets 5. They say the program has no bugs. Explain why more testing is needed.
- 10
A program should turn on a light when it is dark. The code says: if dark = false then turn on light. Find the logic error.
- 11
A loop should play a sound 5 times. The code says: repeat 5 times: play sound, play sound. How many times will the sound play, and what is the bug?
- 12
A spelling program should accept the word cat. The code checks if the word is equal to cot. What kind of bug is this, and how can it be fixed?
- 13
A robot should reach the treasure by moving east 2 spaces and north 1 space. The code is: move east 1, move north 1. Find the missing step.
- 14
A program should print every even number from 2 to 10. It prints 2, 4, 6, 8, 11. What is the output bug?
- 15
A classmate says, "Debugging means deleting all the code and starting over." Write a better explanation of debugging.
More CS Worksheets
CS: Algorithms and Flowcharts
Grade 6-8 · 12 problems
CS: Arrays and Lists
Grade 9-12 · 12 problems
CS: Big-O Notation and Algorithm Efficiency
Grade 9-12 · 12 problems
CS: Binary Numbers and Number Systems
Grade 6-8 · 12 problems
More Grade 4-5 Worksheets
Fractions: Parts of a Whole
Math · 8 problems
Word Problems: Mixed Operations
Math · 8 problems
Food Chains & Ecosystems
Biology · 8 problems
Grammar: Parts of Speech
Language Arts · 8 problems