Week 4 Flashcards
Reducing duplication of code is one of the advantages of using a loop structure.
True
A good way to repeatedly perform an operation is to write the statements for the task once and then place the statements in a loop that will repeat as many times as necessary.
True
In a flowchart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that is tested.
True
The first line in a while loop is referred to as the condition clause.
False
In Python, an infinite loop usually occurs when the computer accesses an incorrect memory address.
False
Both of the following for clauses would generate the same number of loop iterations.
True
The integrity of a program’s output is only as good as the integrity of its input. For this reason, the program should discard input that is invalid and prompt the user to enter valid data.
True
Functions can be called from statements in the body of a loop and loops can be called from within the body of a function.
False
In a nested loop, the inner loop goes through all of its iterations for each iteration of the outer loop.
True
To get the total number of iterations in a nested loop, add the number of iterations in the inner loop to the number in the outer loop.
False
A while loop is called a pretest loop because the condition is tested after the loop has had one iteration.
False
What type of loop structure repeats the code a specific number of times?
a. condition-controlled loop
b. number-controlled loop
c. count-controlled loop
d. Boolean-controlled loop
c. count-controlled loop
What type of loop structure repeats the code based on the value of Boolean expression?
a. condition-controlled loop
b. number-controlled loop
c. count-controlled loop
d. Boolean-controlled loop
a. condition-controlled loop
What are the values that the variable num contains through the iterations of the following for loop?
for num in range(2, 9, 2):
a. 2, 3, 4, 5, 6, 7, 8, 9
b. 2, 5, 8
c. 2, 4, 6, 8
d. 1, 3, 5, 7, 9
c. 2, 4, 6, 8
What are the values that the variable num contains through the iterations of the following for loop?
for num in range(4):
a. 1, 2, 3, 4
b. 0, 1, 2, 3, 4
c. 1, 2, 3
d. 0, 1, 2, 3
d. 0, 1, 2, 3
Which of the following is not an augmented assignment operator?
a. *=
b. /=
c. +=
d. <=
d. <=
A variable used to keep a running total is called a(n)
a. accumulator
b. total
c. running total
d. summer
a. accumulator
_________ 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. Input validation
b. Correcting data
c. Data validation
d. Correcting input
a. Input validation
A(n) __________ structure is a structure that causes a statement or a set of statements to execute repeatedly.
a. sequence
b. decision
c. module
d. repetition
repetition
The first operation is called the __________ and its purpose is to get the first input value that will be tested by the validation loop.
a. priming read
b. first input
c. loop set read
d. loop validation
a. priming read
When will the following loop terminate?
while keep_on_going != 999:
a. when keep_on_going refers to a value less than 999
b. when keep_on_going refers to a value greater than 999
c. when keep_on_going refers to a value equal to 999
d. when keep_on_going refers to a value not equal to 999
c. when keep_on_going refers to a value equal to 999
In Python, a comma-separated sequence of data items that are enclosed in a set of brackets is called
a. sequence
b. variable
c. value
d. list
d. list
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. target variable
b. loop variable
c. for variable
d. count variable
a. target variable
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
c. total += number