Chapter 4 Flashcards

(25 cards)

1
Q

What is a repetition structure?

A

A structure that makes the computer repeat included code as necessary

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

What are the two broad categories of loops?

A

Condition-controlled loops and count-controlled loops

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

What is a condition-controlled loop?

A

A loop that repeats while a Boolean condition is true

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

What is a count-controlled loop?

A

A loop that iterates a specific number of times

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

What is the syntax of a while loop in Python?

A

while condition:
statements

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

What is an iteration?

A

One execution of the body of a loop

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

What is a pretest loop?

A

A loop that tests its condition before performing an iteration (e.g., while loop)

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

What is an infinite loop?

A

A loop that never ends because the stopping condition is never met

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

How do you use a while loop as a count-controlled loop?

A

Use a counter variable with initialization, comparison, and update steps

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

What are the three actions in a count-controlled loop?

A

Initialization, comparison, and update

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

What is the syntax of a for loop in Python?

A

for variable in [val1, val2, …]:
statements

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

What is the purpose of the target variable in a for loop?

A

To reference each item in a sequence as the loop iterates

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

What does the range() function do?

A

Generates an iterable sequence of values for use in for loops

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

What arguments can range() take?

A

One argument: ending limit

Two arguments: start and end

Three arguments: start, end, and step

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

What is an accumulator variable?

A

A variable that keeps a running total inside a loop

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

What are augmented assignment operators?

A

Shorthand operators that update variables (e.g., +=, -=, *=, /=)

17
Q

What is a sentinel?

A

A special value marking the end of a sequence of items

18
Q

What is input validation?

A

Inspecting input before processing to ensure it is valid

19
Q

What does GIGO stand for?

A

Garbage in, garbage out

20
Q

How are input validation loops typically implemented?

A

With a while loop that repeats as long as input is invalid

21
Q

What is a nested loop?

A

A loop contained inside another loop

22
Q

How do you calculate total iterations in a nested loop?

A

Multiply iterations of the inner loop by iterations of the outer loop

23
Q

What does the break statement do?

A

Immediately terminates a loop

24
Q

What does the continue statement do?

A

Ends the current iteration early and moves to the next iteration

25
What is the purpose of the else clause in loops?
Executes if the loop terminates normally (not by break)