Skip to content

Exercises

1.1 — Write about_me.py that prints three lines: your name, your city, and the number of programming languages you know (as a number, not text).

1.2 - Write the same program as above, but this time to this instead:

  • ask the user to enter their name and store this in a variable
  • ask the user to enter their city and store this in a variable
  • ask the user their favorite programming language and store this in a variable
  • print this information to the screen

1.3 — Predict, then run: what does each line print?

print(5 * 3)
print("5" * 3)
print("5" + "3")
print(5 + 3, "apples")

1.4 — The following script has a bug. Read the traceback, say which error types it is, and fix it:

print("Balance:" + 250)

1.5 — Use print to draw a small box exactly like this, using string repetition ("*" * n) — not by typing 10 stars by hand:

**********
*        *
**********

Homework

H1.1 — Write receipt.py that prints a mock receipt: a title line, a line of dashes made with string repetition, two item lines, and a total. Use print's multiple-argument form so numbers and text mix cleanly.