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

Week 11 — Text That Says What It Means — 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 10 of the term — split a line of text into pieces, find and count what is inside it, catch a method whose new string was thrown away, and explain it all to someone who has never programmed.

This week you learned that a string method hands back a new string and never changes the old one, that split() makes a list and join() makes a string, that find() hands back a position or -1, and that count() counts every match. In this assignment you trace four short problems, run each one to check your prediction, run three more programs that show what a piece of text really holds, and explain a real mix-up to someone who has never programmed. This builds on Week 3 and Week 9. This week's lecture tutorial, quiz, discussion, and Coding Lab practise the same ideas from other angles.

The task

A neighbor who runs a weekend bike-repair stall posted a sign-up note for volunteers and wrote a short program to count how many times the note asks people to bring something:

note = "  Bring water, bring snacks, BRING a hat  "
note.strip().lower()
print(note.count("bring"))

It printed 1. Your neighbor says, "Python can only find one of the three." 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 and 3 use the stall's repair log line, line = "fixed: 12 tires, 5 chains".

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 line entry = "day 3: 25 pages" is split with parts = entry.split(), and the program runs print(int(parts[2]) + 5). What does it print?
  2. The repair log's line is split with pieces = line.split(), and the program runs print(int(pieces[1]) + int(pieces[3])). What does it print?
  3. The program runs print(line.find("tires")) on the repair log's line. What does it print?
  4. Your neighbor's program is fixed so the second line reads clean = note.strip().lower() and the last line reads print(clean.count("bring")). What does it print?

Beside each answer, add one brief interpretation:

  • Problem 1: state what type parts[2] holds before int() converts it, and report what print(parts[2] + "5") prints when you run it.
  • Problem 2: state how many items pieces holds, and explain why the comma stays attached to the word tires.
  • Problem 3: explain what kind of value find() hands back, and report what print(line.find("brakes")) prints when you run it.
  • Problem 4: run your neighbor's original version, report what it prints, name the bug, and explain why the one-line change fixes it.

Explain it to a non-programmer

Write a 3–5 sentence message to your neighbor that explains, in everyday words, why Python seemed to find only one of the three, and how changing one line fixes it. Use the idea that a tidied-up copy of the note is a new piece of text that has to be kept, not a change to the note itself, and name one limit or caveat, such as the fact that counting also finds the letters inside a longer word like bringing. Explain any technical term in everyday words. More than one good message is possible.

For a different, ungraded example, imagine a roommate whose grocery app splits a shopping list on spaces when the list was typed with commas. Model message: "Your app cuts the list wherever it sees a space, the way you told it to, so a two-word item like olive oil turns into two separate items, and the commas stay glued to the words. Python did exactly what the instruction said, which is why there was no error message, only a strange list. If you tell it to cut at the commas instead, each item stays whole. One catch: any spaces typed after the commas stay at the front of each item until you trim them."

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

Show your traces. A reader should be able to follow every prediction step by step and see the actual output of your run beside it, without guessing which piece of the line each position holds or what each method handed back.

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 print(parts[2] + "5"), print(line.find("brakes")), and your neighbor's original version, each with what printed; and
  • your message to your neighbor, explaining why only one request was found, how changing one line 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