Ch4 Test Bank Answers Repetition Structures - Test Bank | Python 5e by Gaddis by Tony Gaddis. DOCX document preview.

Ch4 Test Bank Answers Repetition Structures

Starting Out with Python 5e (Gaddis)

Chapter 4 Repetition Structures

TRUE/FALSE

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

2. 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.

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

4. The first line in a while loop is referred to as the condition clause.

5. In Python, an infinite loop usually occurs when the computer accesses an incorrect memory address.

6. 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):

7. 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.

8. Functions can be called from statements in the body of a loop and loops can be called from within the body of a function.

9. In a nested loop, the inner loop goes through all of its iterations for each iteration of the outer loop.

10. 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.

11. A while loop is called a pretest loop because the condition is tested after the loop has had one iteration.

12. In order to draw an octagon with turtle graphics, you would need a loop that iterates eight times.

MULTIPLE CHOICE

1. 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

2. 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

3. 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

4. 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

5. Which of the following is not an augmented assignment operator?

a.

*=

b.

/=

c.

+=

d.

<=

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

a.

accumulator

b.

total

c.

running total

d.

summer

7. __________ 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

8. 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

9. 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

10. When will the following loop terminate?

while keep_going != 999:

a.

when keep_going refers to a value less than 999

b.

when keep_going refers to a value greater than 999

c.

when keep_going refers to a value equal to 999

d.

when keep_going refers to a value not equal to 999

11. 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

12. 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

13. 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

14. What will be displayed after the following code is executed?

total = 0

for count in range(1,4):

total += count

print(total)

a.

1

3

6

b.

5

c.

1 4

d.

6

15. What will be displayed after the following code is executed?

total = 0

for count in range(4,6):

total += count

print(total)

a.

4

9

b.

4

5

6

c.

4

5

d.

9

16. 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

counting

c.

counting

counting

d.

counting

counting

counting

17. What will be displayed after the following code is executed?

for num in range(0, 20, 5):

num += num

print(num)

a.

30

b.

25

c.

0 5 10 15 20

d.

5 10 15

18. What does the following program do?

student = 1

while student <= 3:

total = 0

for score in range(1, 4):

score = int(input("Enter test score: "))

total += score

average = total/3

print("Student ", student, "average: ", average)

student += 1

a.

It accepts 4 test scores for 3 students and outputs the average of the 12 scores.

b.

It accepts 3 test scores for each of 3 students and outputs the average for each student.

c.

It accepts 4 test scores for 2 students, then averages and outputs all the scores.

d.

It accepts one test score for each of 3 students and outputs the average of the 3 scores.

COMPLETION

1. A(n) ___________ structure causes a set of statements to execute repeatedly.

2. A(n) __________-controlled loop causes a statement or set of statements to repeat as long as the condition is true.

3. The while loop is known as a(n) __________ loop because it tests the condition before performing an iteration.

4. A(n) ___________ loop usually occurs when the programmer does not include code inside the loop that makes the test condition false.

5. In Python, you would use the __________ statement to write a count-controlled loop.

6. A(n) __________ total is a sum of numbers that accumulates with each iteration of the loop.

7. A(n) __________ is a special value that marks the end of a sequence of items.

8. The acronym __________ refers to the fact that the computer cannot tell the difference between good data and bad data.

9. A(n) __________ validation loop is sometimes called an error trap or an error handler.

10. The ___________ function is a built-in function that generates a list of integer values.

11. The following for loop iterates ___________ times to draw a square.

for x in range(4):

turtle.forward(200)

turtle.right(90)

Document Information

Document Type:
DOCX
Chapter Number:
4
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 4 Repetition Structures
Author:
Tony Gaddis

Connected Book

Test Bank | Python 5e by Gaddis

By Tony Gaddis

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party