Bird
Raised Fist0
Intro to Computingfundamentals~20 mins

Debugging mindset in Intro to Computing - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Debugging Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ trace
intermediate
2:00remaining
Trace the output of a simple debugging scenario

Consider the following code snippet that calculates the sum of numbers from 1 to 5 but has a subtle bug. What will be the output?

Intro to Computing
total = 0
for i in range(1, 6):
    total += i
print(total)
A10
B15
C0
D5
Attempts:
2 left
💡 Hint

Remember that range(1, 5) includes numbers from 1 up to but not including 5.

🧠 Conceptual
intermediate
2:00remaining
Identify the cause of a runtime error

What is the most likely cause of the following error message when running this code?

IndexError: list index out of range

Code snippet:

numbers = [10, 20, 30]
print(numbers[3])
Intro to Computing
numbers = [10, 20, 30]
print(numbers[3])
ATrying to access an element beyond the list length
BUsing a wrong variable name
CSyntax error in the code
DDividing by zero
Attempts:
2 left
💡 Hint

Check the list length and the index used.

❓ Comparison
advanced
2:00remaining
Compare debugging approaches for a logic error

Which debugging approach is best to find why a program calculating average scores gives wrong results?

AAdd print statements to check intermediate values during calculation
BRewrite the entire program from scratch
CIgnore the problem and run the program again
DChange variable names randomly to see if it fixes the issue
Attempts:
2 left
💡 Hint

Think about how to find where the calculation goes wrong step-by-step.

❓ identification
advanced
2:00remaining
Identify the type of bug from a code snippet

What type of bug is present in the following code?

def divide(a, b):
    return a / b

result = divide(10, 0)
print(result)
Intro to Computing
def divide(a, b):
    return a / b

result = divide(10, 0)
print(result)
ATypo in function name causing failure
BSyntax error because of missing colon
CLogic error producing wrong output
DRuntime error due to division by zero
Attempts:
2 left
💡 Hint

What happens when dividing by zero in Python?

🚀 Application
expert
3:00remaining
Debugging a complex scenario with multiple errors

Given the following code, what will be the output or error?

def process(data):
    total = 0
    for i in range(len(data)):
        total += data[i]
    return total // len(data)

values = [10, 20, '30', 40]
print(process(values))
Intro to Computing
def process(data):
    total = 0
    for i in range(len(data)):
        total += data[i]
    return total // len(data)

values = [10, 20, '30', 40]
print(process(values))
ASyntaxError due to wrong operator
B100
CTypeError because of adding integer and string
DZeroDivisionError because of division by zero
Attempts:
2 left
💡 Hint

Check the data types inside the list and how addition works.

Practice

(1/5)
1. What is the main goal of having a debugging mindset when working with code?
easy
A. To ignore error messages and keep coding
B. To write code as fast as possible without testing
C. To carefully check and fix code step-by-step
D. To copy code from others without understanding

Solution

  1. Step 1: Understand the purpose of debugging mindset

    Debugging mindset means being careful and systematic in finding and fixing errors in code.
  2. Step 2: Compare options with this purpose

    Only To carefully check and fix code step-by-step matches this careful step-by-step checking and fixing approach.
  3. Final Answer:

    To carefully check and fix code step-by-step -> Option C
  4. Quick Check:

    Debugging mindset = careful step-by-step fixing [OK]
Hint: Debugging means careful step-by-step checking [OK]
Common Mistakes:
  • Thinking debugging is about coding fast
  • Ignoring error messages
  • Copying code without understanding
2. Which of the following is the correct way to write a comment in Python to help with debugging?
easy
A.
B. # This is a comment
C. /* This is a comment */
D. // This is a comment

Solution

  1. Step 1: Identify Python comment syntax

    Python uses the # symbol to start a comment line.
  2. Step 2: Match options with Python syntax

    # This is a comment uses #, which is correct. Others are comment styles for HTML, JavaScript, or C.
  3. Final Answer:

    # This is a comment -> Option B
  4. Quick Check:

    Python comment = # [OK]
Hint: Python comments start with # symbol [OK]
Common Mistakes:
  • Using // or /* */ which are not Python comments
  • Using HTML comment syntax in Python
3. Consider this Python code snippet:
def add_numbers(a, b):
    return a + b

result = add_numbers(3, '4')
print(result)

What will happen when this code runs?
medium
A. It raises a TypeError
B. It prints 34
C. It prints 7
D. It prints null

Solution

  1. Step 1: Analyze the function call with mixed types

    The function tries to add an integer 3 and a string '4'.
  2. Step 2: Understand Python's behavior on adding int and str

    Python cannot add int and str directly, so it raises a TypeError.
  3. Final Answer:

    It raises a TypeError -> Option A
  4. Quick Check:

    int + str = TypeError [OK]
Hint: Adding int and str causes TypeError in Python [OK]
Common Mistakes:
  • Thinking Python concatenates int and str
  • Expecting numeric addition without type conversion
4. You have this JavaScript code:
let count = 0;
for(let i = 0; i < 5; i++) {
  count = count + i;
}
console.log(count);

But the output is always 0. What is the most likely error?
medium
A. The console.log statement is missing
B. The loop condition is wrong, it never runs
C. The variable count is declared with let outside the loop
D. The variable count is reset inside the loop

Solution

  1. Step 1: Check where count is updated

    If count is reset to 0 inside the loop each time, it never accumulates.
  2. Step 2: Identify the cause of output always 0

    Resetting count inside the loop causes it to stay 0 after loop ends.
  3. Final Answer:

    The variable count is reset inside the loop -> Option D
  4. Quick Check:

    Resetting accumulator inside loop = no sum [OK]
Hint: Check if accumulator resets inside loop [OK]
Common Mistakes:
  • Assuming loop never runs
  • Ignoring variable reset inside loop
  • Thinking console.log missing causes no output
5. You want to debug a program that processes a list of numbers but sometimes skips numbers unexpectedly. Which approach best uses a debugging mindset to find the problem?
hard
A. Add print statements inside the loop to trace each number processed
B. Delete the entire code and rewrite it from scratch
C. Ignore the problem and hope it fixes itself
D. Change random parts of the code without testing

Solution

  1. Step 1: Choose a systematic way to observe program behavior

    Adding print statements inside the loop helps see which numbers are processed.
  2. Step 2: Use this information to identify where skipping happens

    Tracing output step-by-step reveals logic errors causing skips.
  3. Final Answer:

    Add print statements inside the loop to trace each number processed -> Option A
  4. Quick Check:

    Trace program flow step-by-step to debug [OK]
Hint: Trace code step-by-step with print statements [OK]
Common Mistakes:
  • Rewriting code without understanding
  • Ignoring errors
  • Changing code randomly without testing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard