U of T · Intro to Programming · Fall

CSC108H1: write it, then make it right.

Python from nothing: types, control flow, functions, lists, dictionaries, classes. The course assumes no prior programming, but it moves fast and it grades style as well as output, because the point is not code that runs — it is code someone else can read.

About this course

The on-ramp to everything computational.

CSC108H1 "Introduction to Computer Programming", per the calendar: programming in a language such as Python; elementary data types, lists, maps; program structure — control flow, functions, classes, objects, methods; algorithms and problem solving; searching, sorting, and complexity; unit testing; floating-point numbers and numerical computation. No prior programming experience required. Leads to CSC148H1, and the pair together satisfies the programming requirement for most mathematics and statistics programs.

Note the exclusions. You cannot take CSC108H1 after or alongside CSC110Y1, CSC111H1, CSC120H1 or CSC148H1, so the CSC108H1 → CSC148H1 route and the CSC110Y1 → CSC111H1 route are alternatives, not a menu to mix.

01

Chapters

In the order the calendar lists the topics. Each page has definitions, worked code, common errors, and practice.

CSC108H1Intro Programming · Fall CSC148H1Intro CS · Winter (sequel) Prereqnone
  1. Values, types & variables

    int, float, str, bool; assignment and names.

    Open →
  2. Control flow

    Conditionals, while and for loops, ranges.

    Open →
  3. Functions

    Definition, parameters, return, scope, docstrings.

    Open →
  4. Strings

    Indexing, slicing, methods, immutability.

    Open →
  5. Lists & aliasing

    Mutation, the aliasing trap, nested lists.

    Open →
  6. Dictionaries & sets

    Maps, keys, inverting, counting patterns.

    Open →
  7. Classes, objects & methods

    Defining a type; __init__, __str__, __eq__.

    Open →
  8. Unit testing & design

    doctest, unittest, and choosing test cases.

    Open →
  9. Searching, sorting & complexity

    Linear vs binary search; big-O as a growth rate.

    Open →
  10. Floating point & numerical computation

    Why $0.1+0.2\ne0.3$, and what to do about it.

    Open →
02

How It Runs

Shape taken from the published Fall 2024 course outline. Weights move year to year, so treat these as the pattern rather than the numbers — check the syllabus on Quercus in September.

The weekly rhythm
Prepare, before lecture

Short videos with embedded exercises, due early in the week. These carry marks, and skipping them means arriving at lecture unable to do the activity.

Perform, after lecture

A second exercise set due at the end of the week, submitted through the course tooling. Best 10 of 11 typically counts, so one bad week is survivable.

Assignments and tests

Three assignments of increasing weight, a term test, and a final. The assignments are where style and docstrings are actually graded.

READ

The error message first

Python names the file, the line, and the kind of failure. Reading it properly is the single highest-return habit in the course, and most beginners skip straight to guessing.

TRACE

By hand, on paper

Write out variable values line by line. Tests in this course ask you to predict output, and tracing is the only reliable method.

DESIGN

Docstring before body

Write the type contract and examples first, then the code that satisfies them. It is graded, and it makes the body easier to write.

SMALL

One thing at a time

Run after every few lines rather than writing fifty and debugging the lot. Beginners lose more time to big-bang debugging than to any concept.

03

Practice Plan

Programming is not learned by reading. The unit pages give exercises; use this course-level mix to build fluency.

01

Type it, do not copy it

Retype every example from the guide rather than pasting. The typos you make are the errors you will learn to read.

02

Predict, then run

Before pressing run, write down what you expect. When it differs, you have found a gap worth closing.

03

Break it deliberately

Feed the empty list, the empty string, zero, and a negative number to everything you write. That is also how the graders choose test cases.

04

Reread your week-one code

Every few weeks, reopen an early exercise and rewrite it with what you now know. It is the fastest way to see progress.

Course-wide challenge bank

These mix tracing, writing and debugging in the style the term test asks for.

Challenge 1 · Trace it

What does this print?

python
xs = [1, 2, 3]
ys = xs
ys.append(4)
print(len(xs))
Answer
4. ys = xs does not copy the list; both names refer to the same object, so appending through one is visible through the other. This is aliasing, and it is Unit 5's entire subject.
Challenge 2 · Write it

Write a function returning the number of vowels in a string.

Solution
python
def count_vowels(s: str) -> int:
    """Return the number of vowels in s.

    >>> count_vowels('hello')
    2
    """
    return sum(1 for ch in s.lower() if ch in 'aeiou')
The docstring with an example is not decoration here; it is what doctest runs and what the assignment marks.
Challenge 3 · Fix it

Why does this never stop?

python
i = 0
while i < 5:
    print(i)
Answer
Nothing changes i, so the condition stays true forever. Add i = i + 1 inside the loop. Every while needs something in the body that moves it toward the exit condition.
Challenge 4 · Explain it

Why is 0.1 + 0.2 == 0.3 False?

Answer
Floats are binary fractions, and $0.1$ and $0.2$ have no exact binary representation, so the stored values are slightly off and the sum lands slightly past $0.3$. Compare with a tolerance instead: abs(a - b) < 1e-9. Unit 10 covers this.
04

Resources

CSC108H1 — official calendar listing
Department of Computer Science — undergraduate
Published Fall 2024 course outline (PDF)

Topic list quoted from the Arts & Science calendar; course structure taken from the published Fall 2024 outline. The department does not publish a required textbook for every offering, and marking weights change year to year. Verify everything against the syllabus posted on Quercus in the first week.

CSC108H1 · INTRO TO PROGRAMMING · U OF T SEQUEL: CSC148H1