Back to the Introduction to Computer Science outline The Course Maker
Introduction to Computer Science outline
Week 15 · Coding Lab

Week 15 — Coding Lab / Programming Studio · "Build an Object"

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: Objective 8 — define a class and create & use objects · SLO A (write & run) + SLO B (trace & debug)
Worth 50 points · Coding Labs group = 15% of the grade · Coding Lab 15
Format: a hands-on programming studio in a free online Python environment — you'll (a) write, (b) trace code and predict its output, and (c) find and fix a bug — then catch the AI's mistake.

Everything runs in your browser — nothing to install. The habit: run it and read what Python actually prints.


Part 1 — The Big Picture

This week you build your own kind of object. This lab makes it concrete: you'll define a class, create objects with their own attributes, call methods, watch each object keep its own state, and fix the #1 OOP bug — forgetting self.

Your tools: 🔗 https://www.online-python.com/ (write & run) and 🔗 https://pythontutor.com/ (visualize).


Part 2 — (a) Write

Write each program, run it, and paste your code + output.
1. A Dog class. Write a Dog class whose __init__ stores a name, and a method speak(self) returning name + ' says Woof!'. Create Dog('Rex') and print speak().
2. A Rectangle with area. Write a Rectangle class storing width and height, with an area(self) method. Print the area of a 3-by-4 rectangle.
3. A BankAccount that remembers. Write a BankAccount class storing a balance, with a deposit(self, amount) method. Create one with 100, deposit 50, and print the balance.


Part 3 — (b) Trace: Predict, Then Run

Predict each output first (don't run yet!), then run each and fill in "Actual."

# Program Your prediction Actual
1 Dog('Rex').speak() (from your class) ______ ______
2 Rectangle(3, 4).area() ______ ______
3 after a = BankAccount(100); a.deposit(50), print a.balance ______ ______
4 two Counters: c1 incremented twice, c2 once → print(c1.count, c2.count) ______ ______
5 a Cat whose init writes name = name (no self.), then Cat('Milo').speak() ______ ______

Hint for #5: without self., where did the name go? Run it and read the last line of the error.


Part 4 — (c) Find & Fix the Bug

This class is supposed to print Milo says Meow but crashes. Run it, then write (i) the error type, (ii) why, and (iii) a fixed version.

class Cat:
    def __init__(self, name):
        name = name
    def speak(self):
        return self.name + ' says Meow'
print(Cat('Milo').speak())

Part 5 — Analysis Questions

  1. In #4, why is c1.count 2 but c2.count 1, even though they're the same kind of object?
  2. In #5, the name was passed into __init__ — so why did self.name not exist when speak() ran?
  3. What is the difference between the class Dog and the object Dog('Rex')?
  4. Every method's first parameter is self. When you call d.speak(), who provides the self argument — you, or Python?
  5. Connect it: you've used strings and lists all term, each with their own data and methods. How is a BankAccount object (data + methods bundled together) the same idea as a string or a list?

Part 6 — AI-Critique Moment (required — this is the BYOAI step)

Bring in your approved chatbot and check its work.
1. Ask it: "Write a BankAccount class with a deposit method, create an account with $100, deposit $50, and print the balance."
2. Run its code and check: did it store the balance with self.balance (or forget self.AttributeError)? Did it include __init__? Is the final balance the correct 150?
3. Write 2–3 sentences on what it got right and one thing you had to correct or verify by running it.

The habit: the tool drafts, you run it and judge. Catching the AI's slip — by running the code — is the point.


Part 7 — What to Submit

Your Part 2 programs + outputs; your completed Part 3 trace table; your Part 4 bug answers; your Part 5 answers; and your Part 6 AI-critique paragraph. Due Sunday Dec 13, 11:59 p.m.**** (50 points).


Instructor answer key & model outputs — REMOVE BEFORE PUBLISHING TO STUDENTS

Execution gate: PASS — every output below was produced by running the code.

Part 3 trace table (run-verified):

# Actual output
1 Rex says Woof!
2 12
3 150
4 2 1
5 AttributeError: 'Cat' object has no attribute 'name'

Part 4 bug (run-verified): (i) AttributeError ('Cat' object has no attribute 'name'); (ii) name = name in __init__ just reassigns a local variable — it never stores the value on the object, so self.name doesn't exist when speak() runs; (iii) fix — self.name = name:

class Cat:
    def __init__(self, name):
        self.name = name
    def speak(self):
        return self.name + ' says Meow'
print(Cat('Milo').speak())   # -> Milo says Meow

Part 5 analysis (expected): (1) c1 and c2 are independent objects, each with its own count attribute. (2) name = name never stored anything on the object — only self.name = name does. (3) Dog is the blueprint (class); Dog('Rex') is a specific object built from it. (4) Python provides self automatically when you write d.speak(). (5) a BankAccount bundles data (balance) with methods (deposit) — exactly like a string bundles its characters with methods (.upper()) or a list bundles its items with methods (.append()); they're all objects.

Grading rubric — 50 points

Criterion Full Partial None
Part 2 — wrote & ran 3 classes (Dog, Rectangle, BankAccount; correct outputs) (14) 14 7–11 0–5
Part 3 — trace table (predictions attempted + all 5 actual outputs correct from running) (14) 14 7–11 0–5
Part 4 — found & fixed the missing-self bug (error type + why + self.name fix) (12) 12 6–10 0–4
Part 5 — analysis (independent objects; why self. matters; class vs object; who passes self; objects everywhere) (6) 6 3–5 0–2
Part 6 — AI-critique (names a specific thing checked/corrected by running) (4) 4 2 0–1

Quality gate (self-checked): every model output above was produced by running the codeexecution gate: PASS.

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