Chapter 4 Repetition Structures Flashcards

1
Q

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

A

counting
counting
counting
counting

Chapter 4 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
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

A

total += number

Chapter 4 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A while loop is called a pretest loop because the condition is tested after the loop has had one iteration.
True or False?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A variable used to keep a running total is called a(n)

a. accumulator
b. running total
c. summer
d. total

A

accumulator

Chapter 4 Q (page 179)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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?

A

True

Chapter 4 Q

Tree arguments for the range function:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

0, 1, 2, 3

Chapter 4 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A

repetition

Chapter 4 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
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?

A

False

Chapter 4 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following is not an augmented assignment operator?

a. *=
b. <=
c. /=
d. +=

A

<=

Chapter 4 Q (page 181)

\+= 
-=
*=
/=
%=
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In a flowchart, both decision structure and the repetition structure use the diamond symbol to represent the condition that is tested.

A

True

Chapter 4 Q

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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

A

target variable

Chapter 4 Q (page# 170)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly