I. Conditionals (if/elif/else)
Concept Syntax Key Rule
Example
Basic if if: Code runs ONLY if the condition is True.
if/elif/else if c1: ... elif c2: Only ONE branch executes. The program executes the
... else: ... code block for the FIRST condition that is True, then
immediately skips the rest of the block.
Precedence if x > 1: ... elif Order Matters! If x=5, the x > 1 branch is executed, and
x > 3: ... the x > 3 branch is ignored because the first condition was
met.
II. Loops
A. While Loops
Concept Syntax Example Key Rules
Basic while condition: Executes as long as the condition
while remains True.
Loop Requires a variable to be initialized
Control before the loop. This variable must be
updated inside the loop to eventually
make the condition False.
Infinite while True: This loop runs forever unless
Loop stopped by a break statement or a
return statement (which exits the
whole function).
B. For Loops
Concept Syntax Example Key Rules
, Iteration for char in "Missouri": Executes once for each element (character)
over String in the sequence. Variable char automatically
takes on the value of the next element.
range() range(start, stop, step) Generates a sequence of numbers.
Function
range() 1. stop is Exclusive: Counting
Rules goes up to but NOT including
the stop value.
2. Defaults: If omitted, start
defaults to 0, and step defaults
to 1.
range() Call Output Sequence (What's Printed)
range(5) 0, 1, 2, 3, 4
range(1, 20, 5) 1, 6, 11, 16
range(0, 12*n + 1, n) 0, n, 2n, ..., 12n
III. Strings and Input
Concept Syntax / Example Key Rule
Input Type user_input = The input() function ALWAYS returns data as the
input('Enter:') string type, regardless of what the user types. You
must use int() or float() to convert it for math.
Indexing "Missouri"[0] -> 'M' Characters are accessed by their index, starting at 0.
Concept Syntax Key Rule
Example
Basic if if: Code runs ONLY if the condition is True.
if/elif/else if c1: ... elif c2: Only ONE branch executes. The program executes the
... else: ... code block for the FIRST condition that is True, then
immediately skips the rest of the block.
Precedence if x > 1: ... elif Order Matters! If x=5, the x > 1 branch is executed, and
x > 3: ... the x > 3 branch is ignored because the first condition was
met.
II. Loops
A. While Loops
Concept Syntax Example Key Rules
Basic while condition: Executes as long as the condition
while remains True.
Loop Requires a variable to be initialized
Control before the loop. This variable must be
updated inside the loop to eventually
make the condition False.
Infinite while True: This loop runs forever unless
Loop stopped by a break statement or a
return statement (which exits the
whole function).
B. For Loops
Concept Syntax Example Key Rules
, Iteration for char in "Missouri": Executes once for each element (character)
over String in the sequence. Variable char automatically
takes on the value of the next element.
range() range(start, stop, step) Generates a sequence of numbers.
Function
range() 1. stop is Exclusive: Counting
Rules goes up to but NOT including
the stop value.
2. Defaults: If omitted, start
defaults to 0, and step defaults
to 1.
range() Call Output Sequence (What's Printed)
range(5) 0, 1, 2, 3, 4
range(1, 20, 5) 1, 6, 11, 16
range(0, 12*n + 1, n) 0, n, 2n, ..., 12n
III. Strings and Input
Concept Syntax / Example Key Rule
Input Type user_input = The input() function ALWAYS returns data as the
input('Enter:') string type, regardless of what the user types. You
must use int() or float() to convert it for math.
Indexing "Missouri"[0] -> 'M' Characters are accessed by their index, starting at 0.