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

Week 3 — Coding Lab / Programming Studio · "Ask, Slice, Fix"

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 2 — read input with input(), build output with f-strings, index & slice strings, use len, and read an IndexError/TypeError · SLO A (write & run) + SLO B (trace & debug)
Worth 50 points · Coding Labs group = 15% of the grade · Coding Lab 3
Format: a hands-on programming studio worked in a free online Python environment — you'll (a) write an interactive f-string greeting, (b) trace index/slice expressions and predict their output, and (c) find and fix a bug — and then catch the AI's mistake when it traces a slice.

This is the course's signature weekly component. Every instructional week has one Coding Lab. Everything runs in your browser — nothing to buy or install. The whole habit of this lab (and this course): don't guess what a slice does — run it and read what Python actually prints.


Part 1 — The Big Picture

This week your programs learned to talk to a person: ask a question with input(), take what they type, and build a personalized answer with an f-string. You also learned to reach into a string — pull out a character (s[0], s[-1]), slice out a chunk (s[1:4]), and measure it (len(s)). This lab is the three core moves, one each: you'll write an interactive program, trace slice/index expressions (predict, then run), and debug the week's classic bug — forgetting that input() always returns a string. The trap to respect all lab: the slice stop is exclusives[1:4] stops before index 4.

Your tools (both free, both in the browser):
- An online Python editor to write and run code: 🔗 https://www.online-python.com/ (or 🔗 https://www.programiz.com/python-programming/online-compiler)
- Python Tutor to watch a slice happen step by step: 🔗 https://pythontutor.com/ — paste a program, click Visualize Execution, then step forward.


Part 2 — Setup (2 minutes)

  1. Open the online Python editor in a new tab.
  2. Delete any sample code so you have a blank editor.
  3. Type and run this:
    python name = input("Your name: ") print(f"Hi {name}, welcome to CS1!")
    When it pauses, type your name in the console and press Enter. You should see your name in the greeting. You just wrote an interactive program. 🎉

Part 3 — (a) Write: An Interactive Greeting

Write each of these in the editor, run it, and paste your code and its output into your submission. (For input programs, note what you typed.)

  1. Greeting. Write a program that asks for the user's name with input() and prints a greeting using an f-string that includes the name (for example, Hi Maria, glad you're here!). Run it and type a name.
  2. Two-field f-string. Ask for the user's name and favorite food (two input() calls) and print one sentence with an f-string, e.g. Maria's favorite food is pizza. Run it.
  3. Length, then last letter. Write a program with s = "PROGRAM" that prints, on three lines: the length of s, the first character, and the last character (use len, s[0], and s[-1]). Run it and write down what it printed.

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

Use the fixed string s = "PROGRAM" for every row. Here is the index ruler — keep it handy:

 +---+---+---+---+---+---+---+
 | P | R | O | G | R | A | M |
 +---+---+---+---+---+---+---+
   0   1   2   3   4   5   6
  -7  -6  -5  -4  -3  -2  -1

For each expression below, first write your predicted output in the table (don't run it yet!). Then run each one (put s = "PROGRAM" at the top of your file and print(...) each expression) and fill in the "Actual" column. Where your prediction and the actual output differ, that's the lesson.

# Expression Your prediction Actual (after running)
1 s[0] ______ ______
2 s[-1] ______ ______
3 s[-2] ______ ______
4 s[2:5] ______ ______
5 s[:4] ______ ______
6 s[3:] ______ ______
7 s[::2] ______ ______
8 len(s) ______ ______

Hint for #4: count carefully — the slice goes up to but not including the stop index. The classic mistake is including one character too many.

Visualize one: paste s = "PROGRAM" and print(s[2:5]) into Python Tutor and step through it. Watch which positions the slice pulls.


Part 5 — (c) Find & Fix the Bug

Each program below is broken. For each one: run it (type the sample input where needed), read the error (bottom line first!), then write (i) the error type, (ii) why it happened, and (iii) the fixed program.

Bug A (run it and type 20 when it asks for your age)

age = input("Your age: ")
print("In 10 years you will be", age + 10)

Bug B (uses s = "PROGRAM", which has 7 characters)

s = "PROGRAM"
print(s[7])

Part 6 — Analysis Questions

Answer in a sentence or two each:
1. In the trace table, which prediction did you get wrong (if any)? What did you learn from the gap? (If you're like most people, #4 or #7 is the culprit.)
2. Why does s[2:5] give three characters and not four? Explain the rule about the slice's stop in your own words.
3. In Bug A, the program crashed with a TypeError. What does that tell you about what input() returns, and how does int(...) fix it?
4. In Bug B, "PROGRAM" has 7 characters but s[7] crashed. Why? What's the largest valid index, and how could you safely get the last character instead?
5. Connect it: both bugs are really the same kind of mistake in disguise — a value isn't the type or position you assumed. How does "run it and read the error" help you catch both?


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

Now bring in your approved chatbot (Gemini, Claude, or ChatGPT) and be the programmer who checks its work.

  1. Paste this to the chatbot: "For s = "PROGRAM", what is the exact output of print(s[2:5]), print(s[::2]), and print(s[-2])? Give me each one."
  2. Check every claim by running each program yourself in the editor:
    - Did it get the slice right (s[2:5] is OGR, not OGRA)? Chatbots routinely include the exclusive stop and add one extra character.
    - Did it trace the step slice (s[::2] is PORM — positions 0, 2, 4, 6)?
    - Did it get the negative index (s[-2] is A)?
  3. Write 2–3 sentences reporting what the AI got right and at least one thing you had to correct or verify carefully — most likely the off-by-one on s[2:5]. If it happened to get everything right, say how you confirmed each one by running it — that's the skill.

The habit all term: the tool drafts, you run it and judge. A chatbot will confidently miscount a slice's exclusive stop — catching it by running the code is the entire point of this course.


Part 8 — What to Submit

Submit a single document (or text entry) with: your Part 3 programs and their outputs (note what you typed); your completed Part 4 trace table (both columns); your Part 5 bug answers (error type, why, and the fix for each); your Part 6 answers; and your Part 7 AI-critique paragraph. Due Sunday, Sep 20, 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 actually running the code in Python. Students' Part 3 wording varies; grade those on "does it run and produce the right kind of output."

Part 3 (model):
1. Reads a name and greets with an f-string, e.g. name = input("Your name: ") / print(f"Hi {name}, glad you're here!") → with Maria typed, Hi Maria, glad you're here!. ✓ (exact words vary; must use input() + an f-string)
2. Two inputs + one f-string, e.g. print(f"{name}'s favorite food is {food}.") → with Maria / pizza, Maria's favorite food is pizza.. ✓
3. s = "PROGRAM"; print(len(s))7; print(s[0])P; print(s[-1])M. ✓

Part 4 trace table (run-verified, s = "PROGRAM"):

# Expression Actual output
1 s[0] P
2 s[-1] M
3 s[-2] A
4 s[2:5] OGR
5 s[:4] PROG
6 s[3:] GRAM
7 s[::2] PORM
8 len(s) 7

Part 5 bugs (run-verified):
- Bug A age = input("Your age: ") / print("...", age + 10) (typed 20) → (i) TypeError (can only concatenate str (not "int") to str); (ii) input() always returns a string, so age is '20', and age + 10 tries to glue a number onto text; (iii) fix: age = int(input("Your age: ")) then print("In 10 years you will be", age + 10) → with 20 typed, In 10 years you will be 30.
- Bug B s = "PROGRAM" / print(s[7]) → (i) IndexError (string index out of range); (ii) "PROGRAM" has length 7, so valid indices are 0–6 and 7 is one past the end; (iii) fix: use the last valid index s[6], or better s[-1]M.

Part 6 (expected): (1) most commonly #4 (OGR, not OGRA) or #7 (PORM). (2) The slice's stop is exclusive, so s[2:5] includes positions 2, 3, 4 (= 5 − 2 = 3 characters) and stops before index 5. (3) The crash means input() returned a string, so age + 10 mixed text and a number; int(...) converts the string to a number so the math works. (4) "PROGRAM" has 7 characters with indices 0–6, so s[7] is one past the end (IndexError); the largest valid index is len(s) - 1 = 6, and the safe way to get the last character is s[-1]. (5) In both bugs Python did exactly what was written — added a number to a string, or reached past the end — rather than guessing the intent; running it and reading the last line of the error names the real problem (TypeError vs IndexError) so you fix the right thing.

Part 7 (AI-critique): full credit for a specific catch — most commonly the AI saying s[2:5] is OGRA (including the exclusive stop) instead of OGR, or mis-stepping s[::2]. Full credit also if the student verified each AI claim by running it.

Grading rubric — 50 points

Criterion Full Partial None
Part 3 — wrote & ran 3 programs (code + output; #1–2 use input() + an f-string; #3 uses len/s[0]/s[-1]) (14) 14 7–11 0–5
Part 4 — trace table (predictions attempted + all 8 actual outputs correct from running) (14) 14 7–11 0–5
Part 5 — found & fixed both bugs (error type + why + fix for each: the int(input()) fix and the IndexError) (12) 12 6–10 0–4
Part 6 — analysis (exclusive stop, input-is-a-string, the off-by-one last index) (6) 6 3–5 0–2
Part 7 — AI-critique (names a specific thing checked/corrected by running — ideally the slice off-by-one) (4) 4 2 0–1

Quality gate (self-checked): every model output above (Hi Maria..., Maria's favorite food is pizza., 7, P, M, A, OGR, PROG, GRAM, PORM, the Bug A fix 30) and both error types (TypeError, IndexError) were produced by actually running the code in Pythonexecution gate: PASS. No output is hand-traced. The lab grades the student's process (write → run → trace → debug), not a single fixed wording for the open-ended Part 3.

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