Questions: Functions: Decomposing Problems

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A function called process_student_data reads a CSV file, calculates each student's average, converts averages to letter grades, and prints a formatted report. What is the primary design problem?

AThe function name is too long and should be shortened
BThe function violates single responsibility — it does four distinct things that should each be separate functions
CThe function should use global variables instead of reading files internally
DThere is no problem — combining all steps in one function makes the code easier to follow
Question 2 Multiple Choice

The same 12-line calculation logic appears in three different places in a program. What is the most important reason to extract it into a single function?

ATo reduce the total line count and make the file smaller
BSo that fixing a bug in the logic only requires one change, not three
CFunctions run faster than inline code, improving performance
DTo prevent other programmers from reading the calculation logic
Question 3 True / False

Small functions that each do mainly one thing are inefficient in real programs and should be avoided in favor of fewer, larger functions.

TTrue
FFalse
Question 4 True / False

If you find yourself writing a comment like '# now calculate the average' before a block of code, that block is likely a good candidate to extract into a named function.

TTrue
FFalse
Question 5 Short Answer

What does 'single responsibility' mean for a function, and why does it make the function easier to test in isolation?

Think about your answer, then reveal below.