University of Free Knowledge

The Forge · Computer Science & Programming

Programming I: First Programs in Python

Variables, loops, and functions — enough Python to make the machine do your errands. · QA 76.73 · ~24 h

FolioUnit I — Talking to the Machine
fol. 1 A List of Instructions the Machine Obeys

A program is an ordered list of statements the computer carries out exactly, one after another from top to bottom.

9 min
fol. 2 A Name Bound to a Value

A variable is a name bound to a value, and every value carries a type — int, float, str, or bool — that fixes what can be done with it.

10 min
fol. 3 Print Out, Input In

print() sends text to the screen while input() reads one line back from the person, always handing it over as a string.

10 min
FolioUnit II — Expressions and Decisions
fol. 4 Recipes That Compute a Value

An expression combines values and operators into a single computed value, evaluated under fixed precedence rules.

11 min
fol. 5 True, False, and the Tests Between

Comparison operators and the connectives and, or, and not reduce values to True or False — the two answers every decision is built on.

12 min
fol. 6 Choosing Which Lines Run

An if / elif / else statement runs exactly one branch, chosen by the first boolean test that comes out True.

12 min
FolioUnit III — Repetition
fol. 7 Repeat While It Holds

A while loop repeats its body as long as a condition stays true, so the body must eventually make that condition false.

12 min
fol. 8 Once for Each Item

A for loop binds a variable to each item a sequence like range() hands it, running the body exactly once per item.

12 min
fol. 9 Following the Counter by Hand

Tracing a loop line by line in a table reveals how the counter grows and where an off-by-one boundary error slips in.

11 min
FolioUnit IV — Functions and Structure
fol. 10 Naming a Block of Steps

Defining a function stores a named block of steps, and calling that name runs those steps wherever you invoke it.

10 min
fol. 11 Values In, One Value Out

Parameters carry values into a function and the return statement hands one value back out to the caller.

11 min
fol. 12 Private Names, Separate Parts

A function's local names are private to its own call, which lets you break a large problem into small, independently testable parts.

11 min
FolioUnit V — Collections, Text and Everyday Algorithms
fol. 13 An Ordered, Changeable Collection

A list is an ordered, index-addressed, mutable collection of values you can read, grow, change, and loop across.

11 min
fol. 14 A Sequence of Characters

A string is an immutable indexed sequence of characters you can slice, search, and rebuild into new strings.

11 min
fol. 15 One Pass, One Accumulator

A single pass through a sequence with an accumulator variable can find the maximum, count matches, or search for a value.

12 min
fol. 16 Reading the Traceback

Debugging is a repeatable method: read the traceback, locate the failing line, form a single hypothesis, and test it.

11 min

The Examination Desk — sit the final →

The Call Slip — search everything Ctrl·K / ⌘K