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