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

Week 2 — Name It, Divide It, Convert It: Tracing Variables and Types — 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 2 of the term — trace short programs that use variables, three kinds of division, a power, and a type conversion, run each one to check, and explain the results to someone who has never programmed.

This week you gave values names, sorted them into types, worked out expressions in the order Python uses, divided three ways, and converted between types on purpose. In this assignment you trace four short programs, run each one to check your prediction, read one error message, and explain the results to someone who has never programmed. This week's lecture tutorial, quiz, discussion, and Coding Lab practise the same ideas from other angles.

The task

Your roommate watched you run the reading log and said, "Python can't make up its mind: you divided 255 by 30 three times and got 8.5, then 8, then 15." Your job is to check that claim the way a programmer would: predict each line before you run it, run it in a free browser Python runner, and explain what Python actually did. All four programs are illustrative.

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

  1. The reading log has goal = 300, pages_read = 45, and pages_left = goal - pages_read, and its last line is print(pages_left / 30). What does that line print?
  2. The same reading log shows that print(pages_left // 30) prints 8, the number of full 30-page days. What does print(pages_left % 30) print?
  3. A lab dish starts with 3 cells, and each cell splits into 2 three times; the program cells = 3 followed by print(cells * 2 ** 3) counts them. What does it print?
  4. A café app stores a bill as bill = 18 and a tip typed by a customer as tip = "4", and its last line is print(bill + int(tip)). What does that line print?

Beside each answer, add one brief interpretation:

  • Problem 1: explain why the output has a decimal point even though both numbers are whole, and say what the number means for the reading log.
  • Problem 2: explain why pages_left // 30 gives 8 instead of rounding 8.5 up to 9, and check your output by multiplying back (8 full days times 30, plus the remainder, should rebuild 255).
  • Problem 3: name the operator Python works out first, and explain why print((cells * 2) ** 3) prints a different number although both lines run without an error.
  • Problem 4: first run print(bill + tip) without the conversion, read the last line of the error message, name the error type, and say whether anything printed; then explain in one sentence what int(tip) changed.

Explain it to a non-programmer

Write a 3–5 sentence message to your roommate that explains, in everyday words, why dividing 255 by 30 gave three different results and why that is not Python changing its mind. Use the idea that the computer does exactly what you wrote, not what you meant, say which operator answers which question, and name one limit or caveat, such as the fact that floor division throws the leftover away, so you need the remainder to see it. Explain any technical term in everyday words. More than one good message is possible.

For a different, ungraded example, imagine four friends splitting 22 slices of pizza, and a friend who asks why a calculator showed 5.5 slices each when the box ran out after 5 slices each. Model message: "Both numbers are right; they answer different questions. 22 ⁄ 4 = 5.5 is the exact share, but nobody cuts a slice in half at a party, so each friend gets 5 whole slices. 4 × 5 = 20 slices are handed out, and 22 − 20 = 2 slices are left over. The exact share is a fair average, but it cannot tell you how many whole slices are left, so you need the leftover count too."

Use that pattern for your roommate'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 values, operators, or order of operations you used.

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 error reading for the unconverted café line, naming the error type from the last line of the error message and saying whether anything printed; and
  • your message to your roommate, explaining which operator answers which question and naming 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