CSC 1001 — Lab 8: Tracing and Fixing Buggy Programs

Intro

You will work with a partner to trace through a small buggy program, agree on what is broken, and figure out why. Then you will each individually attempt a fix and compare your solutions. This lab builds the skill of reading and reasoning about code carefully before changing anything — the same habit you will lean on with any tool, including AI coding assistants, later in the course.

SectionModeWhat You'll Do
UnderstandPartnerTrace a buggy program together and agree on what's broken.
DoIndividualAttempt your own fix independently.
CommunicatePartnerCompare your fix with your partner's and discuss.

Submit: your Lab 8 Worksheet and a notebook or script (Lab8.ipynb) with your fixed program.


Understand (with your partner)


Do (individually)


Communicate (with your partner)

Repeat Understand/Do/Communicate

Complete the same steps for at least 3 total buggy programs.


Appendix: Buggy Programs

Choose one program with your partner. Each program is short on purpose — the goal is careful reading, not reading a lot of code.

Program 1: Letter Grade Assigner

def letter_grade(score: int):
    if score >= 90
        return "A"
    elif score >= 80:
        return "B"
    elif score >= 70:
        return "C"
    else:
        return "F"

print(letter_grade(85))

Program 2: Order Total Calculator

def total_cost(price: float, quantity: int):
    subtotal: float = price * quantity
        tax: float = subtotal * 0.05
    return subtotal + tax

print(total_cost(19.99, 3))

Program 3: Test Score Averager

def average(numbers):
    total: int = 0
    for n in numbers:
        total: int = total + n
    return total / len(numbers)

scores: list[int] = []
print(average(scores))

Program 4: Greeting Builder

def greet(name: str, age: int):
    message = "Hello " + name + ", you are " + age + " years old."
    return message

print(greet("Sam", 19))

Program 5: Even Number Counter

def count_evens(numbers: list[int]):
    count: int = 0
    for i in range(1, len(numbers)):
        if numbers[i] % 2 == 0:
            count = count + 1
    return count

print(count_evens([2, 4, 6, 8, 10]))

Program 6: Passing Score Checker

def is_passing(score: int):
    if score < 60:
        return True
    else:
        return False

print(is_passing(75))

Program 7: Shipping Fee Estimator

def shipping_fee(weight: int, distance: int):
    base_fee: int = 5
    fee: float = base_fee + weight * 0.5
    return fee

print(shipping_fee(10, 200))