Repetition structures Flashcards

1
Q

What type of loop structure repeats the code based on the value of Boolean expression?

condition-controlled loop
number-controlled loop
list-controlled loop
count-controlled loop

A

condition-controlled loop

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

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
FALSE

A

TRUE

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

To get the total number of iterations of a nested loop, sum the number of iterations of all the loops.

TRUE
FALSE

A

FALSE

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

It is not possible to do a post-test loop using while in Python.

TRUE
FALSE

A

FALSE

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

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

TRUE
FALSE

A

TRUE

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

In a for loop, the main purpose of a _____ variable is to reference each item in a sequence as the loop iterates.

target
reference
running
accumulator

A

target

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

The loop in the following code is called _____
while True:
print(‘Reading….’)

Finite loop
True loop
Infinite loop
Definite loop

A

Infinite loop

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

In input validation loops, the first input operation is called the _____, and its purpose is to get the first input value that will be tested.

loop validation
prompting read
loop jumpstart
priming read

A

priming read

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

A _____ is a special value that marks the end of a sequence of items.

sentinel
running total
break
target variable

A

sentinel

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

The while loop is known as a pretest loop, which means it tests its condition before performing an iteration.

TRUE
FALSE

A

TRUE

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

Reducing the duplication of code is one of the advantages of using a loop structure.

TRUE
FALSE

A

TRUE

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

Both of the following clauses would generate the same number of loop iterations.
for num in range(4):
for num in range(1,5):

TRUE
FALSE

A

TRUE

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

What are the values that the variable num contains through the iterations of the following for loop?
for num in range (2,9,2):

2 ,4, 6, 8
1, 3 ,5, 7, 9
2, 5, 8
2, 3, 4, 5, 6, 7, 8, 9

A

2, 4, 6, 8

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

Input validation
Correcting data
Correcting input
Data validation

A

Input validation

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

When will the following terminate?
while keep_on_going != 999:

when keep_on_going refers to a value less than 999
when keep_on_going refers to a value not equal to 999
when keep_on_going refers to a value equal to 999
when keep_on_going refers to a value greater than 999

A

when keep_on_going refers to a value equal to 999

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

total + number = total
total = number
number += number
total += number

A

total += number

17
Q

What will be displayed after the following code is executed?

count = 4
while count < 12:
print(“counting”, end= ‘ ‘)
count = count + 2

counting counting counting counting counting
counting counting counting
counting counting
counting counting counting counting

A

counting counting counting counting

18
Q

What will be displayed after the following code is executed?

for num in range(0, 20, 5):
num += num
print(num)

5 10 15
30
25
0 5 10 15 20

A

30