Jupyter Notebook exercises for Python programming
Click “launch binder” above to launch the exercises in Binder, a read-only environment for Jupyter Notebooks. This means that your progress will be erased when the browser tab is closed. Please download the notebook files you wish to keep: right-click on the file and click "Download".
This programming guide for Python beginners is part of a guided lesson package for H2 Computing students, with a greater focus on programming methodology over Python feature coverage.
For exercises with a focus on learning Python features quickly, see Intro to Python.
The exercises are provided here, sans guidance.
The following topics are covered:
- Introduction [X]
int,float, and arithmetic operatorsbooland comparison operatorsstr, the concatenation and repetition operators- output
- Abstraction [X]
- expressions and statements
- constants
- defining functions and parameters
- functions vs procedures
- variable scoping
- Selection [X]
- input
if-elif-else- logical operators
- Recursion [X]
- features of successful recursion
randomfunctions for generating pseudorandom numbers
- Iteration [X]
- Conditional iteration with
while - Fixed iteration with
for - slicing
- Conditional iteration with
- Data structures and mutability [X]
- Sequences using
list - Mappings using
dict listvstuplevsstr- mutable vs immutable objects
randomfunctions for working with sequences
- Sequences using
- Debugging [X]
- trace tables and
print()statements - the
pdbdebugger
- trace tables and
- Identity [X]
- Identity with the
id()function ==vsis
- Identity with the
- File IO: working with files and directories [X]
- getting file handles from
open() - file modes: read, write, and append
- getting file handles from
- Error handling with
try[X]
- Handling CSV files with
csv[X]readerandwriterfor CSV without headerDictReaderandDictWriterfor CSV with header
- Convenience features [X]
- f-strings
- tuple unpacking
enumerate()zip()sorted()reversed()- in-place operators
- Abstraction with modules [X]
- importing modules
__name__- aliasing