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.
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.
Chapters
In the order the calendar lists the topics. Each page has definitions, worked code, common errors, and practice.
- Open →
Values, types & variables
int, float, str, bool; assignment and names.
- Open →
Control flow
Conditionals, while and for loops, ranges.
- Open →
Functions
Definition, parameters, return, scope, docstrings.
- Open →
Strings
Indexing, slicing, methods, immutability.
- Open →
Lists & aliasing
Mutation, the aliasing trap, nested lists.
- Open →
Dictionaries & sets
Maps, keys, inverting, counting patterns.
- Open →
Classes, objects & methods
Defining a type; __init__, __str__, __eq__.
- Open →
Unit testing & design
doctest, unittest, and choosing test cases.
- Open →
Searching, sorting & complexity
Linear vs binary search; big-O as a growth rate.
- Open →
Floating point & numerical computation
Why $0.1+0.2\ne0.3$, and what to do about it.
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.
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.
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.
Three assignments of increasing weight, a term test, and a final. The assignments are where style and docstrings are actually graded.
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.
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.
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.
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.
Practice Plan
Programming is not learned by reading. The unit pages give exercises; use this course-level mix to build fluency.
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.
Predict, then run
Before pressing run, write down what you expect. When it differs, you have found a gap worth closing.
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.
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.
What does this print?
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.Write a function returning the number of vowels in a string.
Solution
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')doctest runs and what the assignment marks.Why does this never stop?
i = 0
while i < 5:
print(i)Answer
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.Why is 0.1 + 0.2 == 0.3 False?
Answer
abs(a - b) < 1e-9. Unit 10 covers
this.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.