Back to the Introduction to Computer Science outline The Course Maker
Introduction to Computer Science outline
Week 7 · Lecture outline

Week 7 — Lecture Outline · Functions

Introduction to Computer Science · CSCI 1101 Fall 2026 · Prof. Okafor Fictional sample

Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Objective covered: Objective 5 — Define functions with def; pass arguments to parameters; return a value and use the result; reason about local vs. global scope.
SLOs touched: A (write and run a correct program — now organized into functions) · B (trace a call and predict its return / printed output, including None; find and fix a function defect)
Meeting pattern: 2 studio sessions × 75 min = 150 min. Segment minutes below total ~150; scale to your own pattern.

Every code output, traced value, return value, and None result in this outline was produced by actually running the code in Python — not hand-traced. Run them live in class; the outputs are exact.

Midterm note: this is the last new topic before the Week 8 Midterm, which is cumulative over Weeks 1–7. Tie functions back to variables, conditionals, and loops as you go — the midterm mixes them.


Week at a Glance

The week's big question "How do I package a piece of work once — give it inputs and get an answer back — so I can reuse it instead of rewriting it?"
By the end of the week, students can… (1) define and call a function with def, passing arguments to parameters; (2) return a value and use the result; (3) tell return from print and predict the None from print(f()) when f doesn't return; (4) reason about local vs. global scope — a variable made inside a function isn't visible outside, and reassigning inside doesn't change the outer variable; (5) handle multiple parameters and argument order, and spot & fix a missing-return/scope bug.
Key vocabulary function, def, define, call/invoke, parameter, argument, pass, return, return value, None, call a function, use the result, local variable, global variable, scope, frame/local namespace, DRY, single responsibility, helper function
Materials slides (Deck 7), the week's readings + video links, a free online Python environment + Python Tutor (links in the readings), one approved chatbot (Gemini / Claude / ChatGPT) for the AI-critique moment and the tutorial
Timing note 8 segments, ~150 min total. Session 1 = Segments 1–4 (~75). Session 2 = Segments 5–8 (~75). This is a studio: code along on the projector and have students type every example into the online environment with you, and call each function so they see the output.

Segment 1 — Hook & the Promise (8 min) · Session 1 opens

Hook. Put three nearly identical blocks on a slide — three places in a program where we compute the area of a rectangle, each time writing w * h again with different numbers, and one of them has a typo (w + h). Ask: "What's wrong with copying this logic three times?" Land it: if the rule lives in three places, a bug lives in three places, and a fix has to happen in three places. Then show the cure: write area(w, h) once, call it three times. "One definition. One place to fix. That's a function."

The promise (write it on the board): "By Friday you'll write your own functions — give them inputs, get answers back — and you'll know exactly why print(f()) sometimes shows None. The habit is the same: define it, call it, run it — don't guess."

Why it matters line (memory hook): "print shows it to a human; return hands it back to the program."


Segment 2 — What Is a Function? def, Parameters & Arguments (20 min)

Plain language first. A function is a named, reusable block of code. You define it once with def, and later you call it to run it. Think of it as a little machine: you feed it inputs and (usually) it gives you back an output.

The anatomy (build it on the board):

def area(w, h):
    return w * h
  • def starts the definition. area is the name. w and h in the parentheses are parameters — named placeholders for the inputs.
  • The indented body is what runs when you call it — not now. "Defining a function doesn't run it. It just teaches Python the recipe."

Calling it — and the parameter/argument distinction (the vocabulary students mix up):

result = area(3, 4)
print(result)

Output (run-verified):

12
  • The values you pass in the call — 3 and 4 — are arguments. The names in the definition — w and h — are parameters. "Parameters are the labeled slots; arguments are what you drop into them. w gets 3, h gets 4."
  • The memory line: "parameters are in the def; arguments are in the call."

Why we bother (callback to the hook): define once, call many. area(3, 4), area(10, 2), area(5, 5) — one definition, three calls, zero copy-paste. That's DRY: don't repeat yourself.


Segment 3 — return: Get an Answer Back (the code-along) (24 min)

Set it up: "Open the online Python environment. Type exactly what I type. We're going to build a function, call it, and use what it gives back."

Code-along, step by step (everyone types each line and runs it):

Step 1 — define and call a greet function with a parameter:

def greet(name):
    print("Hello,", name)

greet("Sam")
greet("Mara")

Output (run-verified):

Hello, Sam
Hello, Mara

"One definition, two calls, two different arguments. The parameter name becomes Sam, then Mara. This is reuse."

Step 2 — now a function that returns a value instead of printing it:

def area(w, h):
    return w * h

a = area(3, 4)
print(a)

Output (run-verified):

12

"return hands the value 12 back to wherever we called it. We caught it in the variable a, then printed a. The function itself printed nothing — it returned."

Step 3 — the payoff: a return value is just a value, so you can use it anywhere a value goes — including inside a bigger expression:

def area(w, h):
    return w * h

print(area(3, 4) + area(2, 5))

Output (run-verified):

22

"area(3, 4) is 12, area(2, 5) is 10, and 12 + 10 is 22. Because each call returns a number, we can add them. That's the whole point of return — the answer flows back into your program."

Name the loop (put it on a slide): DEFINE the function → CALL it with arguments → USE the value it returns. "Six weeks of writing scripts top-to-bottom; now you can bottle a piece of work and reuse it. This is the biggest organizing tool in the course."


Segment 4 — Trace This Code: What Does It Print? (incl. the None surprise) (20 min) · Session 1 closes (~75)

Set it up: "Before we run a call, a real programmer predicts two things: what does the call print, and what value does it return? Let's trace — then run to check."

Worked trace #1 — return value used in print (predict, then run):

def double(n):
    return n * 2

print(double(10))
  • Trace: double(10) returns 10 * 2 = 20; print displays it.
  • Output (run-verified):
20

Worked trace #2 — the signature None surprise (reveal slowly):

def greet(name):
    print("Hello,", name)

x = greet("Sam")
print(x)
  • Trace, line by line: the call greet("Sam") runs the body, which prints Hello, Sam. But greet has no return, so it hands back the special value None. We stored that in x. Then print(x) displays None.
  • Predicted output: Hello, Sam then None. Run it. Actual (run-verified):
Hello, Sam
None

"This is the classic confusion. The function PRINTED something, so it FEELS like it gave us 'Hello, Sam'. It didn't. A function with no return returns None. print is for showing a human; return is for handing a value back. They are not the same thing — and print(f()) is where you see it."

Worked trace #3 — drive it home with a direct print(f()):

def total(a, b):
    print(a + b)

answer = total(6, 1)
print(answer)
  • Trace: total(6, 1) prints 7 (the body's print), returns None (no return), so answer is None; print(answer) shows None.
  • Output (run-verified):
7
None

"Same lesson, sharper: the 7 is the function printing; the None is what it returned. If you wanted to keep the sum, you needed return a + b, not print(a + b)."

Quick interaction (rapid-fire, ~5 min): put three tiny programs on a slide; for each, students predict both the printed output and the returned value (20 sec), then you run it. Suggested with run-verified outputs:
- print(area(5, 2)) where def area(w,h): return w*h10.
- def show(x): print(x*2) then print(show(4))8 then None.
- def half(n): return n/2 then print(half(7))3.5 (callback to Week 2 — / makes a float).


Segment 5 — Local vs. Global Scope (22 min) · Session 2 opens

Hook back in: "Last session you returned values out of functions. Now: what about the variables inside a function — who else can see them? The answer (scope) trips up everyone, so we'll see it run."

Plain language first. A variable created inside a function lives only inside that function — that's its scope (its local namespace). When the function finishes, those local variables are gone. Code outside the function can't see them.

Live demo #1 — a local variable isn't visible outside:

def set_count():
    count = 10
    print("inside:", count)

set_count()
print(count)

Run it. Output (run-verified):

inside: 10
NameError: name 'count' is not defined

"Inside the function, count exists — we printed 10. The moment we step outside and ask for count, Python has never heard of it: NameError. The variable was local to set_count. Scope is real, and Python enforces it."

Live demo #2 — reassigning inside does NOT change the outer variable (the one that bites people):

score = 100

def reset():
    score = 0
    print("inside:", score)

reset()
print("outside:", score)

Run it. Output (run-verified):

inside: 0
outside: 100

"There are two different scores here. Assigning score = 0 inside reset makes a new local score — it does not touch the outer one. So inside we see 0, but outside, the original score is still 100. Read that twice: assignment inside a function creates a local; it doesn't reach out and change the global."

Land the distinction (put it on a slide):
- Local = created inside a function; visible only there; gone when the function returns.
- Global = created at the top level; readable inside functions, but a plain assignment inside a function makes a new local, not a change to the global.
- The clean way to get a value out of a function is return it — not to "reach in" for a local. "Functions talk to the rest of your program through parameters (in) and return (out). That's the contract."

Misconception + cure:
- ❌ "If I set a variable inside a function, the rest of my program can use it / it changes the outer one."
Cure: no — it's local. To get a value out, return it and catch it: score = reset().


Segment 6 — Spot & Fix the Bug (the debugging demo) (18 min)

Set it up: "Here's a function that's supposed to give back a total but doesn't. Let's debug it — predict, fix, run to confirm."

The buggy program (put it on a slide exactly as is):

def add(a, b):
    total = a + b

result = add(2, 3)
print(result)

Debug it out loud:
1. Predict: many expect 5. Run it. Output (run-verified):

None
  1. Read what happened: the body computes total = a + b = 5, then the function ends. There's no return, so the call hands back None. result is None.
  2. The bug: a forgotten return. The function did the work but never gave the answer back. (Bonus scope point: total was local — it's gone now; you can't reach it from outside either.)
  3. The fix, then run to confirm:
def add(a, b):
    total = a + b
    return total

result = add(2, 3)
print(result)

Output (run-verified):

5

A second quick bug — print where you meant return (let the room solve it):

def make_total(a, b):
    print(a + b)

t = make_total(10, 5)
print("Total is", t)

Run-verified output:

15
Total is None

"The 15 is the function PRINTING. The None is what it RETURNED — so t is None. We wanted the value, so we needed return a + b. Fix it and run: make_total returns 25? No — 10 + 5 is 15, so t becomes 15 and it prints Total is 15. Run it to be sure." Fixed:

def make_total(a, b):
    return a + b

t = make_total(10, 5)
print("Total is", t)

Run-verified output:

Total is 15

Land the key idea: the three function bugs you'll meet all term — (1) forgot return (function yields None), (2) printed inside instead of returning, (3) tried to use a local variable outside the function. All three look fine and all three are caught the same way: run it and read what comes back.


Segment 7 — Misconceptions Round-Up + Quick Interaction (20 min)

Name the misconceptions out loud, then cure each:

  • "print and return do the same thing."
    Cure: print shows a value to a human; return hands it back to the program. A function with no return returns None — so print(f()) shows None.
  • "Defining a function runs it."
    Cure: def only teaches Python the recipe. Nothing in the body runs until you call it: area(3, 4).
  • "Parameters and arguments are the same word for the same thing."
    Cure: parameters are the named slots in the def; arguments are the actual values in the call. w/h are parameters; 3/4 are arguments.
  • "A variable I set inside a function is usable everywhere / changes the outer one."
    Cure: it's local — invisible outside, and assigning inside makes a new local. To get it out, return it.
  • "Argument order doesn't matter."
    Cure: for ordinary positional arguments it absolutely does. subtract(10, 3) is 7; subtract(3, 10) is -7. The first argument fills the first parameter.

Interaction — Predict-then-Run (rapid-fire, ~8 min): put four programs on a slide; students predict each output solo (30 sec), compare with a neighbor (1 min), then you run all four. Suggested with run-verified outputs:
- def power(base, exp): return base ** exp then print(power(2, 3))8.
- def square(n): n * n then print(square(6))None (missing return).
- n = 5 ; def change(): n = 99 ; change() ; print(n)5 (local reassignment).
- def subtract(a, b): return a - b then print(subtract(3, 10))-7 (argument order).
Tally how many the room got right — celebrate the None misses as "this is exactly why we run code."


Segment 8 — Technology Workflow + AI-Critique, Callback & Hand-off (18 min) · Session 2 closes (~75)

Technology workflow — the everyday loop, on demand:
1. Open the free online Python environment (link in the readings). Define your function, then call it — defining alone produces no output.
2. Press Run. Read what it printed — and check what it returned by printing the call: print(f(...)).
3. To watch scope, paste the program into Python Tutor and step forward: a new frame appears for the function with its local variables, then disappears when the function returns. That picture is scope.
4. If a result is None, suspect a missing return (or a print where you meant return). Make one change, run again.

AI-critique moment (students verify, not consume):

Paste this to an approved chatbot: "What does this print? def greet(): print('Hi there!') and then print(greet())."
Then check by running it. Chatbots routinely say a no-return function "returns" the thing it printed — they'll tell you this prints Hi there! and stop, or even claim the call "returns 'Hi there!'". Run it: it prints Hi there! and then None, because greet returns None. Your job all term: the tool drafts, you run it and judge. This is exactly how the weekly Lecture Tutorial and Coding Lab work — you catch the model, not trust it.

Callback + tease:
- Callback: "Today: define with def, pass arguments to parameters, return a value and use it, tell return from print (the None), and reason about scope. That's the last new piece of the first arc of this course."
- Tease next week: "Next week is the Midterm Review & Exam — cumulative over Weeks 1–7: computing, variables & types, I/O & strings, Booleans & conditionals, while, for/range/nested loops, and functions. We'll review by building — small programs that pull several weeks together, the way the midterm will. The exam pairs a study guide, an exam-prep tutorial, and a practice exam."

Hand-off (the week's graded work):
- Lecture Tutorial 7 (AI tutor, share-link submission) — def, parameters/arguments, return, return-vs-print/None, scope.
- Quiz 7 and Discussion 7 ("Break It Into Functions") and Assignment 7 ("Write, Return, Trace, Fix").
- Coding Lab 7 — "Define, Return, Scope" — write two functions with parameters + return, run a predict-then-run table (incl. a None), fix a missing-return/return-vs-print bug, and watch a local frame appear and vanish in Python Tutor.


Instructor FAQ — Common Stumbles

Student says / does Quick cure
"I defined the function but nothing printed." Defining isn't running. They have to call it: area(3, 4). def only stores the recipe.
"print(f()) shows None — why?" f has no return, so it returns None. print inside shows a value; return hands one back. Add return.
Uses print inside when they need the value later. If the program needs the result, return it and catch it (x = f(...)). print just displays and returns None.
"My function did the math but result is None." Forgot return. The body computed a local value but never handed it back. Add return.
Tries to use a variable created inside a function, outside it. It's local — gone after the call, invisible outside (NameError). return it to use it outside.
"I set score = 0 inside the function but outside it's still 100." Assignment inside a function makes a new local; it doesn't change the global. return the new value and reassign.
Mixes up parameters and arguments. Parameters = the slots in def f(w, h). Arguments = the values in the call f(3, 4).
Swaps argument order. Positional arguments fill parameters left-to-right. subtract(10, 3) is 7, subtract(3, 10) is -7.
"The chatbot said it returns the printed text." A no-return function returns None. Run print(f()) and read the real output — that's the AI-critique habit.

Scope flag

This outline stays within Objective 5 (defining functions with def; parameters vs. arguments; return and using the result; return vs. print and the None case; local vs. global scope; multiple parameters and argument order). We deliberately do not cover default/keyword arguments, *args/**kwargs, the global/nonlocal keywords, returning multiple values, or recursion — those are later or out of CS1 scope (recursion is Week 14). Examples use only this-week and prior-week constructs (print, variables & types, arithmetic, comparisons/conditionals, simple loops). Python and its behavior (None, NameError, positional argument binding) are referenced factually; the instructor and institution remain fictional. Every output shown was produced by running the code.

~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com