Programming for Everybody (Python) — Study Notes
Course: Programming for Everybody (Getting Started with Python) — Charles Russell Severance (Dr. Chuck), University of Michigan, on Coursera. Covers Chapters 1-5 of the textbook Python for Everybody.
Style: a concise study guide organized the way the course builds — why we program, variables and expressions, conditionals, functions, loops. Code examples and displayed outputs have been checked with Python 3. This is a study guide, not a lecture transcript.
Notation: >>> marks code you could type in the interpreter. Output follows on the next line. Python multiplication must use *, so two times n is 2 * n. // is floor division and % is the modulo operator. Python 3 — print is a function and requires parentheses.
PART 1 — WHY WE PROGRAM AND HOW COMPUTERS RUN IT
1.1 Why program
Programming is a creative skill: you write instructions and the computer does the repetitive work. The course's promise — computers are very fast but very literal; the skill is telling them exactly what you want, one small step at a time. A programmer looks at a repetitive task and asks: how do I describe this as a series of simple steps?
1.2 Hardware architecture (five components)
- Central Processing Unit (CPU): the part that asks "what next?" and executes instructions — billions of cycles per second on a modern processor.
- Main Memory (RAM): fast, temporary storage — its contents vanish when the power goes off.
- Secondary Memory (disk or flash): slower, persistent storage — saved files live here.
- Input and Output Devices: keyboard, mouse, microphone, screen, and speakers.
- Network Connection: retrieves and stores information on other computers; the textbook treats it as slow, sometimes unavailable secondary storage.
Software is the set of instructions; the CPU fetches instructions and data from memory and executes them.
1.3 The interpreter
Python is taught here as an interpreted language: the interpreter parses source code and can process a statement immediately in interactive mode. Two ways to use it are interactive mode (the >>> shell, good for experimenting) and script mode (a saved .py file run as a program). You do not run a separate compilation command in this course; implementations such as CPython still compile source internally to bytecode before executing it.
1.4 A program is a sequence
A program is a sequence of Python statements that performs a task — like a paragraph of instructions, executed top to bottom, one statement at a time. Errors are bugs; debugging is the craft of reading the traceback, finding the line, and fixing one thing at a time.
Example 1.1 (verified). The traditional first program:
print('Hello world')
Hello world
print is a function; the parentheses run it; the string is what it prints.
1.5 Part 1 checklist
PART 2 — VARIABLES, EXPRESSIONS, AND STATEMENTS
2.1 Constants, reserved words, variables
A constant is a fixed value like 3 or 'hello'. Reserved words are Python's own vocabulary — you cannot use them as variable names: and, as, assert, async, await, break, class, continue, def, del, elif, else, except, False, finally, for, from, global, if, import, in, is, lambda, None, nonlocal, not, or, pass, raise, return, True, try, while, with, yield.
2.2 Variable names and assignment
A variable name must start with a letter or underscore, may contain letters, digits, and underscores, is case-sensitive, and cannot be a reserved word. Good names describe the data: hours, rate, total. An assignment statement stores a value: Python evaluates the RIGHT side first, then stores it in the variable on the left.
Example 2.1 (verified).
x = 2
x = x + 2
print(x)
4
The right side x + 2 uses the old value 2, then 4 overwrites it.
2.3 Numerical expressions and precedence
Operators: + addition, - subtraction, * multiplication, / true division (float result), // floor division, % modulo, ** exponentiation. Precedence: parentheses first, then exponentiation ** (right-associative; -22 is -4, while 2-2 is 0.25), then * / // % (left to right), then + - (left to right). Floor division rounds the quotient down toward negative infinity, so -9 // 5 is -2; it is not simply truncation toward zero.
Example 2.2 (verified).
1 + 2 * 3
7
(1 + 2) * 3
9
9 / 5
1.8
9 // 5
1
9 % 5
4
2 ** 3
8
2 ** 3 ** 2
512
The multiplication happens before addition; parentheses override precedence; exponentiation groups from right to left.
2.4 Types and conversions
type() tells you what a value is: int (whole numbers), float (decimals), str (text). Mixing int and float in an expression produces float. Conversions: int() truncates (int(1.9) is 1 — it does not round), float() adds a decimal, str() turns a number into text for concatenation.
Example 2.3 (verified).
type(1)
<class 'int'>
type(1.0)
<class 'float'>
type('hello')
<class 'str'>
int('3') + 1
4
float(1)
1.0
int(1.9)
1
int() truncates toward zero; it does not round.
2.5 User input and the I-P-O pattern
input() pauses and reads what the user types — and it ALWAYS returns a string. Convert before math: float(input()) or int(input()). The course's first real program follows Input-Process-Output:
Example 2.4 (verified). The pay calculator:
hrs = input('Enter Hours: ')
rate = input('Enter Rate: ')
pay = float(hrs) * float(rate)
print('Pay:', pay)
With 35 hours and rate 2.75, pay prints 96.25.
2.6 Strings and comments
Strings concatenate with + ('Hello ' + 'World') and repeat with * ('Hi ' * 3). A # starts a comment — Python ignores the rest of the line; comments explain why, not what.
2.7 Part 2 checklist
PART 3 — CONDITIONAL CODE
3.1 Boolean expressions
A comparison asks a yes/no question and produces True or False (type bool): < <= > >= == (equal), != (not equal). The single = assigns; the double == asks.
Example 3.1 (verified).
5 == 5 → True
5 != 5 → False
5 > 2 → True
3.2 Logical operators
and is True only if both sides are True; or is True if either is; not flips. x == 1 and y == 3 — both must hold. and and or short-circuit: Python stops as soon as the result is known. This enables a guardian such as x != 0 and y / x > 2, which avoids division by zero.
3.3 Conditional statements
The if statement runs an indented block only when its condition is True. The colon introduces the block, and consistent indentation defines it. Four spaces are the PEP 8 convention, not a syntax requirement. pass is a do-nothing placeholder for an empty block. else covers the False case; elif chains more conditions, checked top to bottom, first True wins.
Example 3.2 (verified). Overtime pay — Worked Exercise 3.2:
hours = float(input('Enter Hours: '))
rate = float(input('Enter Rate: '))
if hours <= 40:
pay = hours * rate
else:
pay = 40 * rate + (hours - 40) * rate * 1.5
print('Pay:', pay)
At 45 hours and rate 10: 40 × 10 + 5 × 15 = 475.0. At exactly 40: 400.0.
3.4 try / except
When input is not a number, float('forty-two') crashes with a traceback. try/except catches the conversion exception and runs the except block instead — the program keeps going. Catch ValueError here so unrelated exceptions are not hidden:
Example 3.3 (verified pattern).
hrs = input('Enter Hours: ')
try:
h = float(hrs)
except ValueError:
h = -1
if h < 0:
print('Error, please enter numeric input')
3.5 Part 3 checklist
PART 4 — FUNCTIONS
4.1 Stored and reused steps
A function is a named, reusable chunk of code. Python ships built-ins: print(), input(), type(), float(), int(), str(), max(), min(), len(). Calling runs the code inside; arguments go in, a result comes back.
Example 4.1 (verified).
big = max('Hello', 'World')
print(big)
World
max compares strings alphabetically — capital W sorts after capital H. len('Hello') is 5; min('Hello', 'World') is 'Hello'.
4.2 Building your own functions
The def statement names a function and lists its parameters; the indented body runs on each call. Parameters and variables assigned inside a function are local by default. A function can still read a global name, while assigning to a global requires an explicit global declaration.
Example 4.2 (verified).
def addtwo(a, b):
... added = a + b
... return added
addtwo(3, 4)
7
4.3 return versus print
return hands a value back to the caller so it can be stored or reused; print only shows text on the screen. A function with no return statement returns None — and a function that only prints still returns None.
Example 4.3 (verified).
def thing():
... print('Hello')
print(thing())
Hello
None
The Hello is the function printing; the None is what thing() returned.
4.4 Part 4 checklist
PART 5 — LOOPS AND ITERATION
5.1 While loops (indefinite)
A while loop repeats as long as its condition is True — you use it when you do not know how many times in advance. There must be a path that eventually makes the condition False or executes break; otherwise the loop runs forever.
Example 5.1 (verified). The countdown:
n = 5
while n > 0:
print(n)
n = n - 1
print('Blastoff!')
Prints 5 4 3 2 1, then Blastoff!
5.2 break and continue
break jumps out of the loop immediately; continue skips the rest of the current iteration. A while loop then rechecks its condition; a for loop advances to the next item.
Example 5.2 (verified pattern).
while True:
line = input('> ')
if line == 'done':
break
print(line)
print('Done!')
Everything typed echoes until the user types done.
5.3 For loops (definite)
A for loop iterates over an iterable — such as a list, string, tuple, range, or file — once per item, with no manual counter needed. range(5) produces 0 1 2 3 4.
Example 5.3 (verified).
for i in [5, 4, 3, 2, 1]:
... print(i)
5 4 3 2 1
friends = ['Joseph', 'Glenn', 'Sally']
for friend in friends:
... print('Happy New Year:', friend)
One greeting per friend — three lines.
5.4 The counting and summing idioms
count = count + 1 counts items; total = total + value sums them. Shorthand: count += 1.
Example 5.4 (verified).
count = 0
total = 0
for value in [3, 41, 12, 9, 74, 15]:
count = count + 1
total = total + value
print(count, total, total / count)
6 154 25.666666666666668 — the exact Python output; the average is approximately 25.67.
5.5 Finding the largest and smallest
The largest-so-far pattern: keep a champion, replace it when something beats it.
Example 5.5 (verified).
largest_so_far = None
for the_num in [9, 41, 12, 3, 74, 15]:
if largest_so_far is None or the_num > largest_so_far:
largest_so_far = the_num
print('Largest', largest_so_far)
Largest 74. The None sentinel works no matter how large or negative the data are. The same pattern works for a minimum: start with smallest = None, and use "is None" to claim the first value.
Example 5.6 (verified).
smallest = None
for value in [9, 41, 12, 3, 74, 15]:
if smallest is None:
smallest = value
elif value < smallest:
smallest = value
print('Smallest', smallest)
Smallest 3. is and is not compare identity — "is None" is the idiomatic check.
5.6 Filtering inside a loop
An if inside the loop picks only what you want:
Example 5.7 (verified).
for value in [3, 41, 12, 9, 74, 15]:
if value > 20:
print('Large number', value)
Prints only 41 and 74.
5.7 Part 5 checklist
APPENDIX A — QUICK REFERENCE
Operators: + - * / // % ** with ** grouping right to left; // is floor division. Comparisons: < <= > >= == !=. Logic: and, or, not with short-circuit evaluation. Built-ins: print, input, type, int, float, str, max, min, len. Conversions: int('3') is 3, float(1) is 1.0, int(1.9) truncates to 1. Conditionals: if / elif / else with a colon and consistent indentation (four spaces by convention); catch ValueError for bad numeric input. Functions: def name(parameters): body; return hands a value back; no return means None; assigned names are local by default. Loops: while for indefinite; for item in iterable for definite; break exits; continue begins the next iteration; idioms count += 1 and total += value; None sentinel for largest/smallest.
APPENDIX B — TRAP LIST
- input() always returns a string. Convert before math or you will concatenate (or crash).
- = assigns; == compares. x = 5 sets it; x == 5 asks.
- int(1.9) truncates to 1 — it does not round to 2.
- / produces a float even between two ints (9 / 5 is 1.8); // floors the quotient (-9 // 5 is -2).
- A colon starts a compound statement and consistent indentation defines its block; four spaces are convention, not mandatory syntax.
- A function that only prints returns None. Store its result and you get None.
- A while loop with no path to a false condition or break is an infinite loop.
largest_so_far = -1 breaks on all-negative lists — use the None sentinel.
- Reserved words (True, None, while...) cannot be variable names; case matters (x and X differ).
- Splitting on hardware: RAM is fast and temporary; disk is slow and permanent — the exam asks which is which.
These are original HyNote study notes for people taking Michigan's Programming for Everybody (Getting Started with Python). They follow the public syllabus (Chapters 1-5 of Python for Everybody). They are not official Michigan materials, and they are not lecture transcripts.