๐ Reading, Predicting, and Debugging Code
Master the art of reading code like a detective! This quiz teaches you how to trace through simple programs, predict what they'll do, spot bugs like off-by-one errors and broken loops, and use systematic debugging to fix them. **What you'll learn:** - How to read and trace code step-by-step - Predict program output before running it - Spot common bugs: off-by-one errors, wrong conditions, missing loops - Use logic to debug and fix broken code
Questions in this quiz
Answers hidden โ play to find out.
- Question 1
Look at the following code. What will the variable
resultbe after the code runs? - Question 2
In the code above, the loop adds the numbers 1, 2, 3, 4, and 5 together.
- Question 3
Look at the following code. What will be printed?
- Question 4
Which of these statements is true about the following code?
- Question 5
This code will print the number 5.
- Question 6
Look at the following code. What is the bug in this code?
- Question 7
Look at the following code. What will the final value of
totalbe? - Question 8
Look at the following code. What will be printed to the screen?
- Question 9
This code will set the variable
answerto 8. - Question 10
Look at the following code. What is the bug?
- Question 11
Look at the following code. How many times will the loop print 'Hello'?
- Question 12
This code will print the word 'Even' when x equals 4.
- Question 13
Look at the following code. What will it print?
- Question 14
Look at the following code. Identify the bug.
- Question 15
An off-by-one error happens when a loop or condition is off by exactly one value, like using
range(1, 5)when you meantrange(1, 6). - Question 16
Look at the following code. What is the output?
- Question 17
Look at the following code. What bug exists in this code?
- Question 18
This code will print the numbers 1, 2, 3, 4, and 5.