CS Grade 4-5

CS: Debugging: Finding and Fixing Errors

Practice spotting mistakes and improving simple programs

View Answer Key
Name:
Date:
Score: / 15

Practice spotting mistakes and improving simple programs

CS - Grade 4-5

Instructions: Read each problem carefully. Find the error, explain what is wrong, and write a fix when asked.
  1. 1

    A program is supposed to print Hello, Sam! The code says: print("Hello, Sam!". Find the error and write the corrected code.

  2. 2
    A robot path on a grid showing a correct right turn and an incorrect left turn.

    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. 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. 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. 5
    A child stands exactly level with a height marker at a ride entrance.

    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. 6
    A visual sequence shows getting bread, opening a jar, spreading peanut butter, and finishing a sandwich.

    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. 7
    An open three-sided square shape shows what happens when one side is not drawn.

    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. 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. 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. 10
    A dark room has the lamp off while a bright room has the lamp on, showing reversed light logic.

    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. 11
    Five repeated loop symbols each contain two speaker icons, showing the sound plays twice per loop.

    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. 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. 13
    A robot on a grid needs one more rightward step after moving right and up to reach a treasure chest.

    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. 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. 15

    A classmate says, "Debugging means deleting all the code and starting over." Write a better explanation of debugging.

LivePhysics™.com CS - Grade 4-5

More CS Worksheets

See all CS worksheets

More Grade 4-5 Worksheets

See all Grade 4-5 worksheets