Last Updated: December 6, 2025
30 quizzes
Complete the code to record an informational message about a user login using the logging module
logging.info()Click an option to fill the blank:
Complete the code to measure how long it takes to run the callable fetch_data once using timeit
duration = timeit.timeit(fetch_data, number=)Click an option to fill the blank:
Complete the code so that pdb will pause execution at this point for interactive debugging
pdb.()Click an option to fill the blank:
Which type of error occurs when code is syntactically valid but produces an incorrect result?
When starting to debug a reported issue, what is the first step in an effective debugging process?
Which command starts a Python script under the pdb debugger from the command line?
Inside pdb, which command executes the current line and stops at the next line in the same function?
Which logging level is most appropriate for detailed information used only during debugging?
What is one main advantage of using logging instead of print statements?
Which built-in module is commonly used to profile CPU time of Python code?
Why is timeit preferred over manually using time.time() for small snippets?
Which tool lets you annotate Python functions with @profile to see line-by-line memory usage?
What is a key purpose of using tracemalloc in a Python application?
Order the steps to use pdb.set_trace() to debug a function inside a script.
Drag and drop to reorder, or use the arrows.
Order the steps to profile a slow_function using cProfile within a script.
Drag and drop to reorder, or use the arrows.
What is the output of this code related to runtime vs logical errors?
1def divide(a, b):
2 try:
3 return a / b
4 except ZeroDivisionError:
5 return "cannot divide"
6
7result = divide(6, 3)
8print(result)What does this code print when using logging with different levels?
1import logging
2logging.basicConfig(level=logging.WARNING)
3logging.debug("debug message")
4logging.error("error message")What is the output when using timeit to measure a tiny operation?
1import timeit
2value = timeit.timeit("1+1", number=1)
3print(int(value == 0))Consider this simplified profiling-like counter. What is printed?
1def counted(n):
2 calls = 0
3 for _ in range(n):
4 calls += 1
5 return calls
6
7print(counted(5))What does this memory-related example print?
1sizes = []
2for i in range(3):
3 data = [0] * (10 ** i)
4 sizes.append(len(data))
5
6print(sum(sizes))This function is meant to log an error when list access fails. Find the bug.
Click on the line(s) that contain the bug.
import logging logging.basicConfig(level=logging.ERROR) def get_item(items, index): try: return items[index] except IndexError as exc: logging.info("Index out of range: %s", exc) return NoneThis code is intended to profile a function using cProfile. Find the bug.
Click on the line(s) that contain the bug.
import cProfile def fetch_all(): total = 0 for i in range(1000): total += i return total if __name__ == "__main__": cProfile.run(fetch_all())Match each pdb command with what it does.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each profiling tool to what it primarily measures.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to configure logging to write DEBUG and higher messages to a file named app.log.
import logginglogging.basicConfig(filename=, level=)logging.debug("debug details")Click an option to fill blank 1:
Complete the code to measure the average time of calling compute() 100 times using timeit.
import timeitaverage = timeit.timeit(compute, number=) / print(average)Click an option to fill blank 1:
Complete the code to start and report basic tracemalloc memory statistics.
import tracemalloctracemalloc.()# ... run some code here ...current, peak = tracemalloc.()print(peak)Click an option to fill blank 1:
Complete the code to decorate a function so that memory_profiler can measure its memory usage.
from memory_profiler import @def load_data(): buffer = [b"x" * 1024] * 1000 return len(buffer)Click an option to fill blank 1:
Click the line where a potential runtime error can occur due to list indexing.
Click on the line to select.
values = [1, 2, 3]position = 5item = values[position]print(item)Click the line most appropriate for setting a breakpoint when debugging an incorrect average calculation.
Click on the line to select.
def calculate_average(numbers): total = sum(numbers) count = len(numbers) average = total / count return average result = calculate_average([10, 20, 30])print(result)