Week 4 Flashcards

1
Q

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

A

True

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

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.

A

True

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

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

A

True

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

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

A

False

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

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

A

False

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

Both of the following for clauses would generate the same number of loop iterations.

A

True

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

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.

A

True

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

A

False

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

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

A

True

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

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.

A

False

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

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

A

False

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

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

A

c. count-controlled loop

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

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

a. condition-controlled loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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):
a. 2, 3, 4, 5, 6, 7, 8, 9
b. 2, 5, 8
c. 2, 4, 6, 8
d. 1, 3, 5, 7, 9

A

c. 2, 4, 6, 8

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

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

A

d. 0, 1, 2, 3

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

Which of the following is not an augmented assignment operator?
a. *=
b. /=
c. +=
d. <=

A

d. <=

17
Q

A variable used to keep a running total is called a(n)
a. accumulator
b. total
c. running total
d. summer

A

a. accumulator

18
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. Input validation
b. Correcting data
c. Data validation
d. Correcting input

A

a. Input validation

19
Q

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

A

repetition

20
Q

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

A

a. priming read

21
Q

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

A

c. when keep_on_going refers to a value equal to 999

22
Q

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

A

d. list

23
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. target variable
b. loop variable
c. for variable
d. count variable

A

a. target variable

24
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

c. total += number

25
Q

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

A

d. 6

26
Q

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

A

d. 9

27
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
counting
c. counting
counting
d. counting
counting
counting

A

b. counting
counting
counting
counting

28
Q

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

A

a. 30

29
Q

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.

A

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

30
Q

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

A

repetition

31
Q

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

A

condition

32
Q

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

A

pretest

33
Q

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

A

infinite

34
Q

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

A

for

35
Q

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

A

running

36
Q

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

A

sentinel

37
Q

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

A

GIGO

38
Q

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

A

input

39
Q

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

A

range