0
0
Intro to Computingfundamentals~20 mins

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

Choose your learning style9 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.