← Back to the Introduction to Computer Science outline The Course Maker
← Introduction to Computer Science outline
Week 15 · Assignment: Traditional alternative (no AI)

Week 15 — The Dock That Never Ran Out — Traditional alternative (no AI)

Introduction to Computer Science Free sample edition
Traditional alternative (no AI), unpublished. In the course this is a separate assignment that ships unpublished beside the adaptive assignment: same objective, no AI. An instructor who prefers it publishes it and unpublishes or deletes the adaptive one, as the note at its top says.

Instructors: publish this instead of the adaptive version if you prefer, and unpublish or delete the adaptive one.

Assignment 14 of the term — trace two objects built from one class, find the line that keeps a count from changing, choose between a method that returns and one that prints, and explain it all to someone who has never programmed.

This week you learned that a class is a blueprint and each object built from it keeps its own state, that __init__ runs when the class is called, that every value an object should remember is stored on self, and that a method which only prints hands back None. In this assignment you trace four short problems, run each one to check your prediction, run the extra programs that show where a count is kept, and explain a real mix-up to someone who has never programmed. This builds on Week 7, where a function with no return handed back None, and on Week 9, where a method such as append changed one particular list. This week's lecture tutorial, quiz, discussion, and Coding Lab practise the same ideas from other angles.

The task

A friend who coordinates a campus bike-share wrote a class to track two docks, then rented three bikes from the north dock and four from the south dock:

class BikeDock:
    def __init__(self, bikes):
        self.bikes = bikes

    def rent(self):
        if self.bikes > 0:
            bikes = self.bikes - 1
            return True
        return False

    def refill(self):
        self.bikes = self.bikes + 1

north = BikeDock(9)
south = BikeDock(5)
north.rent()
north.rent()
north.rent()
south.rent()
south.rent()
south.rent()
south.rent()
print(north.bikes, south.bikes)

It printed the same counts the docks started with. Your friend says, "My rent method runs, it even hands back True, but the count never goes down." Your job is to check what Python really did, the way a programmer would: predict each output before you run it, run it in a free browser Python runner, and explain what happened. All four problems are illustrative; Problem 1 uses this week's reading log, and Problems 2 to 4 use the friend's docks, repaired so that rent stores the new count on self, with two more methods added:

class BikeDock:
    def __init__(self, bikes):
        self.bikes = bikes

    def rent(self):
        if self.bikes > 0:
            self.bikes = self.bikes - 1
            return True
        return False

    def refill(self):
        self.bikes = self.bikes + 1

    def available(self):
        return self.bikes

    def report(self):
        print("bikes left:", self.bikes)

Work these four problems. For each one, write your prediction first, then run the code and write the actual output beside your prediction:

  1. The reading log's Week 15 class is built as mine = ReadingLog(300), then mine.add_day(45), mine.add_day(30), and mine.add_day(25) run, and the program prints mine.pages_left(). What does it print?
  2. The repaired dock is built as north = BikeDock(9), north.rent() runs three times, and the program prints north.bikes. What does it print?
  3. A second repaired dock is built as south = BikeDock(5), south.rent() runs four times, south.refill() runs once, and the program prints south.bikes. What does it print?
  4. After the same calls as Problems 2 and 3, the program runs print(north.available() + south.available()). What does it print?

Beside each answer, add one brief interpretation:

  • Problem 1: name the two attributes __init__ stores on self, and run a second log, yours = ReadingLog(150), built beside mine; report what print(yours.pages_left()) prints after mine's three days, and explain why yours is unaffected.
  • Problem 2: run your friend's original version for the north dock alone, report what print(north.bikes) prints, and name the line in rent that is missing self.
  • Problem 3: add print(north.bikes, south.bikes) after both docks' calls, report what it prints, and explain why the rentals at one dock never change the other.
  • Problem 4: run print(north.report() + south.report()) in place of the last line, report what prints and which exception type ends the run, and then choose: to total the bikes, would you read each dock's bikes attribute, call the returning method available, or call the printing method report? Say why your choice fits best and why one other choice fits less well.

Explain it to a non-programmer

Write a 3–5 sentence message to your friend that explains, in everyday words, why the count never went down and how one change fixes it. Use the idea that each dock keeps its own count, and that a line inside a method must say it is changing this dock's count or the new number is thrown away when the method ends, and name one limit or caveat, such as that a program can run with no error message and still print the wrong number. Explain any technical term in everyday words. More than one good message is possible.

For a different, ungraded example, imagine a café whose loyalty-card program never adds a stamp. Model message: "Your card program works out the new number of stamps every time, but it writes that number on scrap paper instead of on the card, so the card itself never changes. Python did exactly what the instruction said, which is why there was no error message, only a card that always shows zero stamps. If the line says to update this card's stamps, the count goes up with every visit. One catch: a program can run without complaining and still be wrong, so it is worth testing it with a visit or two before anyone relies on it."

Use that pattern for your friend's question, with your own wording and evidence.

Show your traces. A reader should be able to follow every prediction method call by method call and see the actual output of your run beside it, without guessing which object each call changed.

After this assignment

This is the last assignment of the course. Next comes Week 16, the finals week, which carries the cumulative final exam. The final's study guide, its exam-prep tutorial, and the Final Practice Exam help you prepare. The choose-the-method step in Problem 4 is the same move the final asks of you: read a program, pick the course idea that fits, and say why another one fits less well.

Deliverables

Submit a single report containing:

  • the four answers, each with your prediction, the step-by-step trace, the actual output of your run, and the brief interpretation the task names for that problem;
  • the runs of the second reading log, your friend's original dock, both docks' counts, and the printing version, each with what printed; and
  • your message to your friend, explaining why the count never went down, how one change fixes it, and one limit.

Keep it to roughly one page. Clear and correct beats long.

Choose how you show it. Present your report as written text, or as a recorded audio or video explanation of about three minutes with a transcript, or as labelled screen captures of your runs with a short note for each. Every form is graded by the same scoring criteria. Submit in any accessible file type or as a link; a recorded response may be submitted as audio or video with a transcript, or as text.

How you'll be graded

The full analytic rubric is attached to this assignment in Canvas.

Academic integrity and AI use

This version is designed to be completed without AI: make the predictions, run the code, and write the interpretations and the message yourself, without any AI tool. You may use a free browser Python runner, Python Tutor, and the official Python documentation. Submitting AI-generated work as your own, or copying another student's work, is an integrity violation under the course policy.

Built with The Course Maker · samples.thecoursemaker.com