Chapter 4

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/16

flashcard set

Earn XP

Description and Tags

Checkpoints

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

17 Terms

1
New cards

What is a loop iteration?

An execution of the statements in the body of the loop.

2
New cards

Does the while loop test its condition before or after it performs an interation?

Before

3
New cards

How many times will ‘Hello World’ be printed in the following program?

count = 10

while count < 1:

  • print (‘Hello World’)

None. The condition count < 0 will be false to begin with.

4
New cards

What is an infinite loop?

A loop that has no way of stopping and repeats until the program is interrupted.

5
New cards

Rewrite the following code so it calls the range function instead of using the list

[0, 1, 2, 3, 4, 5]:

for x in [0, 1, 2, 3, 4, 5]:

  • print (‘ love to program!’)

for x in range (6):

  • print(‘I love to program!’)

6
New cards

What will the following code display?

for number in range (6):

  • print (number)

0

1

2

3

4

5

7
New cards

What will the following code display?

For number in range (2, 6):

  • print (number)

2

3

4

5

8
New cards

What will the following code display?

for number in range (10, 5, -1)

  • print (number)

10

9

8

7

6

9
New cards

What is an accumulator?

A variable that is used to accumulate the total of a series of numbers.

10
New cards

What will the following code display?

total = 0

for count in range (1, 6):

  • total = total + count

print (total)

15

11
New cards

What will the following code display?

number 1 = 10

number 2 = 5

number 1 = number 1 + number 2

print (number1)

print (number2)

15

5

12
New cards

Rewrite the following statements using augmented assignment operators:

  • quantity = quantity + 1

  • days_left = days_left - 5

  • price = price * 10

  • price = price / 2

quantity += 1

days_left -= 5

price *= 10

price /=2

13
New cards

What is a sentinel?

A sentinel is a special value that marks the end of a list of items.

14
New cards

Why should you take care to choose a distinctive value as a sentinel?

A sentinel value must be unique enough that it will not be mistaken as a regular value in the list.

15
New cards

What does the phrase “garbage in, garbage out” mean?

It means that bad data (grabage) is provided as input to a program, the program will produce bad data (garbage) as output.

16
New cards

What is a priming read? What is its purpose?

It is the input operation that takes place just before an input validation loop. The purpose of the priming read is to get the first input value.

17
New cards

If the input that is read by the priming read is valid, how many times will the input validation loop iterate?

None