Week 7 — Quiz (auto-graded) · Functions
Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Objective tested: Objective 5 — defining functions with def; parameters & arguments; return and using the result; return vs. print (None); local vs. global scope; argument order; debugging a missing return.
Points: 10 (1 each) · Assignment group: Quizzes (10% of grade) · Due: end of Module 7.
This is the human-readable quiz with its vetted answer key and feedback. The import-ready Classic QTI is in
F-quiz-week-07-qti.xml(generated by the shared validated script — parses with 10 items, every single-answer item exactly one correct). Execution gate: PASS — every "what does this print / return?" key below was produced by actually running the code in Python, not hand-traced. The Canvas placement block is at the bottom of this file.Note: functions are the last topic on the Week 8 Midterm (cumulative, Weeks 1–7). These ten items are exactly the kind the midterm draws on.
Blueprint
| # | Type | Concept | Objective |
|---|---|---|---|
| 1 | Multiple choice | Parameters vs. arguments (vocabulary) | 5 |
| 2 | Multiple choice | Predict the return — area(5, 2) with return w * h |
5 |
| 3 | Multiple choice | Predict the output incl. None — print(show(4)) where show only prints |
5 |
| 4 | Multiple choice | return vs. print — why print(f()) shows None |
5 |
| 5 | Multiple answer | True statements about functions, return, and scope |
5 |
| 6 | Matching | Call → result (each run-verified) | 5 |
| 7 | Multiple choice | Scope — reassigning inside doesn't change the outer variable | 5 |
| 8 | True / False | "A variable set inside a function is visible outside" misconception | 5 |
| 9 | Multiple choice | Parameter/argument order — subtract(3, 10) |
5 |
| 10 | Multiple choice | Debugging — a missing return yields None |
5 |
No trick questions; distractors are plausible mis-traces (treating a printed value as the return value, expecting a missing-return function to return the computed number, thinking a local change reaches the global, swapping argument order).
Questions, key, and feedback
Q1 (MC). In def area(w, h): and the call area(3, 4), which statement is correct?
- A. w and h are the arguments; 3 and 4 are the parameters
- B. w and h are the parameters; 3 and 4 are the arguments ✅
- C. w, h, 3, and 4 are all parameters
- D. area is the parameter and w, h are the arguments
Feedback: Parameters are the named slots in the definition (w, h); arguments are the actual values you pass in the call (3, 4). Memory hook: parameters are in the def; arguments are in the call.
Q2 (MC). What does this program print?
def area(w, h):
return w * h
print(area(5, 2))
- A.
7 - B.
10✅ - C.
52 - D.
None
Feedback:area(5, 2)returns5 * 2 = 10, andprintdisplays it. (A adds instead of multiplying; C concatenates the digits; D would be the result only if the function had noreturn. Run-verified:10.)
Q3 (MC). What does this program print?
def show(x):
print(x * 2)
print(show(4))
- A.
8 - B.
8thenNone(on two lines) ✅ - C.
Nonethen8 - D.
44
Feedback:show(4)prints8(its body), but it has noreturn, so it hands backNone; the outerprintthen shows thatNone. So you get8, thenNone. (This is the classicreturn-vs-printtrap. Run-verified:8/None.)
Q4 (MC). A function that only prints a value and has no return statement —
- A. returns the value it printed
- B. returns None ✅
- C. returns the text "None" as a string
- D. causes a SyntaxError
Feedback: print shows a value to a human; it does not hand a value back. A function with no return returns the special value None — which is why print(f()) shows None. (It's the value None, not the string "None", and it's perfectly legal code — no error.)
Q5 (Multiple answer — select all that apply). Which of the following statements are true?
- A. def defines a function but does not run its body — you must call the function to run it ✅
- B. return hands a value back to wherever the function was called ✅
- C. A variable created inside a function can be used anywhere in the program
- D. A function with no return statement returns None ✅
- E. print and return do the same thing
Feedback: Defining ≠ running (A); return hands a value back (B); no return means None (D). C is false — a variable made inside a function is local and isn't visible outside. E is false — print shows a value; return hands one back (they're different jobs).
Q6 (Matching). Each program defines a function and prints a call. Match each call to what the program prints. (Every result was produced by running the code.)
| Call (with its definition) | Prints |
|---|---|
| def add(a, b): return a + b → print(add(4, 5)) | 9 |
| def greet(name): return "Hi " + name → print(greet("Lee")) | Hi Lee |
| def half(n): return n / 2 → print(half(7)) | 3.5 |
| def loud(s): print(s.upper()) → print(loud("ok")) | OK then None |
Feedback: add(4, 5) returns 9; greet("Lee") returns the joined string Hi Lee; half(7) returns 3.5 (a single / always makes a float — Week 2); loud("ok") prints OK but returns None, so the outer print shows OK then None.
Q7 (MC). What does this program print?
n = 5
def change():
n = 99
change()
print(n)
- A.
5✅ - B.
99 - C.
None - D. a
NameError
Feedback: Assigningn = 99insidechangecreates a new localn; it does not change the outer (global)n. After the call, the outernis still5. (To actually change it you'dreturnthe new value and reassign:n = change(). Run-verified:5.)
Q8 (True / False). "A variable created inside a function can be used outside the function, after the function runs."
- True
- False ✅
Feedback: False. A variable created inside a function is local — it exists only inside that function and is gone once the function returns. Using it outside raises NameError. To get a value out, return it.
Q9 (MC). What does this program print?
def subtract(a, b):
return a - b
print(subtract(3, 10))
- A.
7 - B.
-7✅ - C.
13 - D.
None
Feedback: Arguments fill parameters in order:agets3,bgets10, so it returns3 - 10 = -7. (Order matters —subtract(10, 3)would be7. Run-verified:-7.)
Q10 (MC). This function is supposed to return a squared number, but print(square(6)) displays None:
def square(n):
n * n
print(square(6))
What is wrong, and how do you fix it?
- A. n * n is the wrong operator; use n ** 2
- B. The function never returns — add return n * n so it hands the value back ✅
- C. square is a reserved word and can't be used as a name
- D. You must call it as square[6] with square brackets
Feedback: The body computes n * n but never hands it back, so the call returns None. The fix is to return the result: return n * n (then print(square(6)) shows 36). (The operator is fine; square is a legal name; functions are called with parentheses, not brackets. Run-verified: buggy → None, fixed → 36.)
Answer key (quick reference)
| Q | Answer |
|---|---|
| 1 | B |
| 2 | B (10) |
| 3 | B (8 then None) |
| 4 | B (None) |
| 5 | A, B, D |
| 6 | add→9 / greet→Hi Lee / half→3.5 / loud→OK then None |
| 7 | A (5) |
| 8 | False |
| 9 | B (-7) |
| 10 | B (add return) |
Quality gate (self-checked): each single-answer item has exactly one correct option; the multiple-answer item keys A, B, D (and requires C and E unselected); the matching item pairs four calls to four distinct results. Execution gate: PASS — the keys for the predict items (Q2 10; Q3 8/None; Q6 9/Hi Lee/3.5/OK+None; Q7 5; Q9 -7) and the debugging item (Q10 buggy → None, fixed → 36) were each produced by running the code in Python, not hand-traced. Distractors are plausible mis-traces (Q2 None = treating a returning function as non-returning; Q3 8 only = ignoring the returned None; Q7 99 = thinking the local change reaches the global; Q9 7 = swapping argument order).
Item-bank entries (for variants + the midterm/final)
All ten items are tagged course=CSCI1101 · week=7 · objective=5 · topic=functions-parameters-return-scope and deposited in Item Bank: Week 7 — Functions. The midterm (Week 8) and the per-term variant updates draw fresh items from this bank. (Tags: q1 params-vs-args, q2 predict-return, q3 none-case, q4 return-vs-print, q5 true-statements, q6 call-result-match, q7 scope-reassign, q8 local-not-visible, q9 arg-order, q10 missing-return-debug.)
Canvas placement block
canvas_object = Quizzes::Quiz
title = "Week 7 Quiz — Functions"
assignment_group = "Quizzes"
points_possible = 10
grading_type = points
due_offset_days = 6 # 6 days after module start
published = true
shuffle_answers = true
ai_permitted = false # AI is not permitted on quizzes
provenance = "~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com"
F-quiz-week-07-qti.xml) ships inside the course's .imscc package — it lands in the Canvas gradebook on import.~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com