1/29
Flashcards covering key concepts from Chapter 5 on Iteration, including updating variables, while statements, loop patterns, and debugging.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Updating Variables
A common pattern in assignment statements where the new value depends on the old, such as x = x + 1. Requires initialization before updating.
Increment
Updating a variable by adding 1.
Decrement
Updating a variable by subtracting 1.
While Statement
A Python language feature for iteration that repeats a block of code as long as a condition is true.
Iteration
Each execution of the body of a loop.
Iteration Variable
The variable that changes each time the loop executes and controls when the loop finishes.
Infinite Loop
A loop that repeats forever because there is no iteration variable or the terminating condition is never satisfied.
Break Statement
A statement used to jump out of a loop, typically used in infinite loops when an exit condition is met.
Continue Statement
A statement used to skip the current iteration of a loop and jump to the next iteration.
Definite Loop (For Loop)
A loop that iterates through a known set of items, such as a list of words, lines in a file, or a list of numbers.
Indefinite Loop (While Loop)
A loop that continues until some condition becomes False.
Loop Patterns
Common structures for looping through items to find something, like the largest or smallest value.
Counting Loop
A loop that counts the number of items in a list.
Summing Loop
A loop that computes the total of a set of numbers.
Accumulator
A variable used in a loop to add up or accumulate a result.
Maximum/Minimum Loops
Loops designed to find the largest or smallest value in a list or sequence.
None
A special constant value in Python used to mark a variable as 'empty'.
Debugging by Bisection
A debugging technique where you break the program in half to isolate the source of an error.
Counter
A variable used in a loop to count the number of times something happened, initialized to zero and incremented each time.
Initialize
Assigning an initial value to a variable before it is updated in a program.
Infinite loop info
How to avoid : make sure loop control variable is in header (ie while i<= 10: - i is loop ctrl variable , if its not in he header it will continue to infinity)
While loop using boolean operators
poop=0
while not poop xxx: (this means while poop is true cuz poop variable is defined as false) (0 means false)
i
i is a common LOOP CONTROL VARIABLE
How to choose which loop to use
• When you know the number of iterations
use a counter-controlled or definite loop such as “for”
• When the iterations depend on a condition
use a conditional or indefinite loop such as “while”
Is and Is not operators
‘Is’ operator means ‘is the same as’
‘Is not’
How to know what itertion variable to use and when
When you know how many times you want the thing to = for
when you want something to keep going UNTIL something happens = while
ranges
range(stop) - goes from 0 , stops 1 before the stop
range(start,stop) - goes from start to 1 before stop
range(start,stop,+- step)- goes from start to 1 before stop , increases/decreases by step each time
odd/even .py
Add +1 at the end of the range to make python iterate the full range number , not just stop one before
to see is something is even - n %2 (returns a remainder)== 0 obvi if its even theres no remainder
constants
variable name in all caps , BIG_FORHEAD = 5 ; Python recognizes this as a constant.
Break vs continue
Continue - means if x== 5 , pass by ie dont use this , like ignore it and go to the next one
break , if x==5 , stop executing the loop entirely.