Chapter 4 Repetition Structures Flashcards
What will be displayed after the following code is executed?
count = 4
while count < 12:
print(“counting”)
count = count + 2
a. counting
counting
counting
counting
b. counting
counting
counting
c. counting counting counting counting
d. counting
counting
counting
counting
counting
counting
Chapter 4 Q
Which of the following represents an example to calculate the sum of numbers (that is, an accumulator), given that the number is stored in the variable ‘number’ and the total is stored in the variable ‘total’?
a. total + number = total
b. number += number
c. total = number
d. total += number
total += number
Chapter 4 Q
A while loop is called a pretest loop because the condition is tested after the loop has had one iteration.
True or False?
False
Chapter 4 Q (page 165)
The while loop is known as a pretest loop, which means it tests its condition before performing an iteration.
A variable used to keep a running total is called a(n)
a. accumulator
b. running total
c. summer
d. total
accumulator
Chapter 4 Q (page 179)
Both the following for clauses would generate the same number of loop iterations:
for num in range (4):
for num in range (1, 5):
True or False?
True
Chapter 4 Q
Tree arguments for the range function:
What are the values that num contains through the iteration of the following for loop?
for num in range(4)
a. 0, 1, 2, 3, 4
b. 0, 1, 2, 3
c. 1, 2, 3, 4
d. 1, 2, 3
0, 1, 2, 3
Chapter 4 Q
___ is the process of inspecting data that has been input into a program in order to ensure that the data is valid before it is used in a computation.
a. Data validation
b. Correcting input
c. Input validation
d. Correcting data
Input validation
Chapter 4 Q (page# 185)
Input validation is 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. Input validation is commonly done with a loop that iterates a long as an input variable references bad data.
A(n) ___ structure is a structure that causes a statement or a set of statements to execute repeatedly.
a. module
b. decision
c. repetition
d. sequence
repetition
Chapter 4 Q
Functions can be called from statements in the body of a loop and loops can be called from within the body of a function.
True or False?
False
Chapter 4 Q
Which of the following is not an augmented assignment operator?
a. *=
b. <=
c. /=
d. +=
<=
Chapter 4 Q (page 181)
\+= -= *= /= %=
In a flowchart, both decision structure and the repetition structure use the diamond symbol to represent the condition that is tested.
True
Chapter 4 Q
In Python, the variable in the for clause is referred to as the ___ because it is the target of an assignment at the beginning of each loop iteration.
a. for variable
b. target variable
c. count variable
d. loop variable
target variable
Chapter 4 Q (page# 170)