CSC 1001 — Lab 11: Working with Collections

Intro

This week you're integrating what you've just learned about collections (lists, dictionaries, and/or other structured data) into everything you already know. Don't set aside functions, variables, and conditionals just because you're now working with collections — you'll need all of it together.

This is also the first week where your code carries forward to next week's lab, so this is not a week to fall behind or skip. Whatever you build today, you'll be extending soon.

A reminder on AI assistance: use it to supplement your thinking, not replace it. Ask an AI agent to explain an idea, check your logic, or help you get unstuck — but make sure you understand every line you keep. You will be asked to explain and defend your design choices later, so "I don't know, the AI wrote it" won't be an acceptable answer.

SectionModeWhat You'll Do
UnderstandPartner ActivityTrace two buggy code snippets with a partner and propose fixes.
DoIndividual, AI-AssistedBuild a text-based contact list program using the full requirements-to-code process.
CommunicatePartner (Online/Anonymous)Exchange and review contact list programs with an anonymous partner.

Submit: your Lab 11 Worksheet and your Lab11.ipynb notebook (contact list program) — you'll extend this program next week.


Understand (Partner Activity)

Work with your assigned partner for this section.

You are given two code snippets below. For each snippet:

  1. Trace it. Walk through the code line by line exactly as the computer would. Document the state of every relevant variable/collection at each step (a simple table works well).
  2. Find the bug(s). Based on your trace, identify where the code's behavior diverges from what it's supposed to do.
  3. Propose a fix. Explain in words (pseudocode is fine) how you'd fix it. You do not need to implement the fix — and you're welcome to use AI to help you reason about why the bug happens, as long as you can explain it yourselves afterward.

Snippet 1 — Intended purpose: return the average of a list of scores

1 scores: list[int]
2 def average_score(scores):
3     total: int = 0
4     for i in range(1, len(scores)):
5         total += scores[i]
6     return total / len(scores)
7 
8 print(average_score([90, 80, 70, 100]))

Your trace should record: the value of i, scores[i], and total at each pass through the loop, and the final returned value — then compare that to what the correct average should be.

Snippet 2 — Intended purpose: return True if a name is in the roster, ignoring case

 1 name: str
 2 
 3 def is_enrolled(name, roster):
 4     for student in roster:
 5         if student == name:
 6             return True
 7     return False
 8 
 9 roster: list[str]= ["Amir", "beth", "CARLOS", "dana"]
10 print(is_enrolled("carlos", roster))

Your trace should record: each student value compared, whether the comparison succeeds, and the final returned value — then compare that to what the function is supposed to return.

Record your traces, the bugs you found, and your proposed fixes (in words/pseudocode) on your Lab 11 Worksheet. One submission per pair is fine — just list both partners' names.


Do (Individual, AI-Assisted)

Now you'll build something of your own: a text-based contact list program.

Requirements

Your program must:

The Process (this must be documented — don't skip steps!)

Work through each of the following stages in order, recording your work on your Lab 11 Worksheet and in Lab11.ipynb as noted:

  1. Requirements — In your own words, restate what the program needs to do. Be specific enough that someone else could build it from your description alone. Record this on your Lab 11 Worksheet.
  2. Subtasks — Break the problem into smaller pieces (e.g., "add a contact," "count contacts by first-letter of first name," "display all contacts"). List them on your worksheet.
  3. Pseudocode — Write out your plan step-by-step in plain language/pseudocode before you write actual Python, on your worksheet. This is where you and an AI agent might collaborate — but the plan should make sense to you.
  4. Code — Implement your program in Lab11.ipynb. Use functions to organize your subtasks. Comment where helpful.

Reflection Question

In a short paragraph on your worksheet, answer:

Why did you choose the collection type that you did (e.g., list of dictionaries, list of tuples, a dictionary of dictionaries, parallel lists, etc.)? Looking back, do you think this choice helped or hindered you as you built out the counting features? Would you choose differently next time?


Communicate (Partner — Online/Anonymous)

You'll now be paired anonymously with a partner online to exchange and review each other's contact list programs.

  1. Read their design choice. Your partner will share their code and their explanation of why they chose their collection type. Do you think they made the right call? Why or why not?
  2. Stress-test their code. Try some contact data they may not have thought of — empty inputs, contacts with only an email and no phone, unusual capitalization, duplicate names, a first/last name that's a single letter, etc. Does the code hold up?
  3. Write two short reviews (2–4 sentences each):
    • Code review: What worked? What didn't? What would you recommend they change about the implementation?
    • Program review: What worked? What didn't? What would you recommend they change about the program's design or behavior (e.g., how it handles input, what it reports, usability)?

Record on your Lab 11 Worksheet: your two short written reviews, submitted with your partner's (anonymous) identifier as instructed by your professor.

Reflection (Individual)

Record on your Lab 11 Worksheet: Your answers to the reflection questions.