1/30
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
repetition structure
causes a statement or set of statements to execute repeatedly
condition-controlled loop
uses a true/false condition to control the number of times that it repeats
count-controlled loop
repeats a specific number of times
while loop
consists of a condition that is tested for a true or false value and a statement or set of statements that is repeated as long as the condition is true
What is the output for this code?
spam = 0
while spam < 5:
print("Hello, World.")
spam = spam + 1Hello, World.
Hello, World.
Hello, World.
Hello, World.
Hello, World.
pretest loop
a loop that tests its conditions before performing an iteration
ex: while loops
True or false: loops don’t need a way to terminate
false
infinite loops
loops that continue to repeat until the program is interrupted
usually occur when the programmer forgets to write code inside the loop that makes the condition false
for loop
used to iterate over a sequence and execute a block of code for each item in that sequence
target variable
the variable that is used in the for clause; it is the target of an assignment at the beginning of each loop iteration
What is the output of this code?
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)apple
banana
cherry
True or false: the values that appear in a list do not have to be a consecutively ordered series of numbers
true
range()
generates a sequence of integers within a specified range
range() syntax
range(start, stop, step)
start and step are optional
Which part of the range() function is inclusive?
start
Which part of the range() function is exclusive?
stop
What is the default for start in the range() function?
0
What is the default for step in the range() function?
1
How do you use decrements in the range() function?
by using a negative step value
What is the output for this code?
for n in range(0,5):
print(n)0
1
2
3
4
What is the purpose of the target variable in a for loop?
to reference each item in a sequence of items as the loop iterates
running total
a sum of numbers that accumulates with each iteration of a loop
accumulator
the variable used to keep the running total
What does the accumulator contain when the loop finishes?
the total of the numbers that were read by the loop
What happens if the accumulator starts with any value other than 0?
it will not contain the correct total when the loop finishes
sentinel
a special value that marks the end of a sequence of values
input validation
the process of inspecting data that has been input to a program, to make sure it is valid before it is used in a computation
nested loop
a loop inside another loop
How many times does the inner loop go through all its iterations?
for every single iteration of an outer loop
True or false: inner loops complete their iterations faster than outer loops
true
How do you get the total number of iterations for a nested loop?
multiply the number of iterations of all the loops