Starting Out w/ Python: Ch. 5
A(n) _______________ validation loop is sometimes called an error trap or an error handler.
Input
In Python, a comma-separated sequence of data items that are enclosed in a set of brackets is called a _____. a. sequence b. variable c. value d. list
d. list
In Python, you would use the _______________ statement to write a count-controlled loop.
for
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
What is not an example of an augmented assignment operator? a. *= b. /= c. -= d. <=
d. <=
The variable used to keep the running total is called a(n) _____. a. Accumulator b. Total c. running total d. grand total
a. Accumulator
What type of loop structure repeats the code based on the value of the Boolean expression? a. Condition-controlled loop b. Number-controlled loop c. Count-controlled loop d. Boolean-controlled loop
a. Condition-controlled loop
_____ 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. a. Input validation b. Correcting data c. Data validation d. Correcting input
a. Input validation
A(n) _______________-controlled loop causes a statement or set of statements to repeat as long as a condition is true.
Condition
Functions can be called from statements in the body of a loop, and loops can be called from the body of a function.
FALSE
In Python, an infinite loop usually occurs when the computer accesses the wrong memory address.
FALSE
The first line in the while loop is referred to as the condition clause.
FALSE
The acronym _______________ refers to the fact that the computer cannot tell the difference between good data and bad data.
GIGO
A(n) _______________ loop usually occurs when the programmer forgets to write code inside the loop that makes the test condition false.
Infinite
The while loop is known as a(n) _______________ loop because it tests conditions before performing an iteration.
Pretest
The _______________ function is a built-in function that generates a list of integer values.
Range
A(n) _______________ structure causes a statement or set of statements to execute repeatedly.
Repetition
A(n) _______________ total is a sum of numbers that accumulates with each iteration of a loop.
Running
A(n) _______________ is a special value that marks the end of a sequence of items.
Sentinel
A better 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 the statements as many times as necessary.
TRUE
Both of the following for clauses would generate the same number of loop iterations: for num in range(4): for num in range(1,5):
TRUE
In a nested loop, the inner loop goes through all of its iterations for every single iteration of an outer loop.
TRUE
In flowcharting, the decision structure and the repetition structure both use the diamond symbol to represent the condition that is tested.
TRUE
Reducing duplication of code is one of the advantages of using a loop structure.
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 correct data.
TRUE
To get the total number of iterations of a nested loop, multiply the number of iterations of all the loops.
TRUE
The first input 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
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
What is the format for the while clause in Python? a. while condition b. while condition : c. while condition statement d. while condition : statement
b. while condition :
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 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 is the disadvantage of coding in one long sequence structure? a. Duplicated code makes the program faster to write. b. Writing a long sequence of statements is error prone. c. If parts of the duplicated code have to be corrected, the correction has to be made many times. d. It does not make use of decision structures.
c. If parts of the duplicated code have to be corrected, the correction has to be made many times.
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
Which of the following represents an example to calculate the sum of the numbers (accumulator)? a. total + number = total b. number += number c. total += number d. total = number
c. total += number
What is the structure that causes a statement or a set of statements to execute repeatedly? a. Sequence b. Decision c. Module d. Repetition
d. Repetition