Week 5 Quiz
The reading log starts at 45 pages, aims for 300, and adds 30 pages a day. What do the two print lines show?
goal = 300 pages_read = 45 days = 0 while pages_read < goal: pages_read = pages_read + 30 days = days + 1 print(days) print(pages_read)Select one.
- 8, then 285
- 9, then 300
- 9, then 315
- 10, then 345
Predict the counter's final value. What does the last line print?
count = 1 while count <= 5: count = count + 1 print(count)Select one.
- 4
- 5
- 7
- 6
The body adds 1 and then prints. What does this program print?
count = 3 while count < 5: count = count + 1 print(count)Select one.
- 4 only
- 4, then 5
- 3, then 4
- 4, then 5, then 6
How many lines does the loop body print before the loop ends?
count = 1 while count < 5: print(count) count += 1Select one.
- 4
- 5
- 3
- 6
The accumulator total collects each value of n. What does the last line print?
total = 0 n = 1 while n <= 5: total += n n += 1 print(total)Select one.
- 10
- 15
- 21
- 5
This loop looks for the first whole number whose square is greater than 50. What does it print?
n = 1 while True: if n * n > 50: print(n) break n = n + 1Select one.
- 7
- 49
- 64
- 8
This loop was meant to print 1 to 5. Select every statement that is true about it.
count = 1 while count <= 5: print(count)Select every option that applies.
- It prints 1 again and again and never stops on its own.
- It prints 1 to 5 and then stops.
- Pressing Ctrl+C in a terminal, or the Stop button in a browser runner, ends the run.
- Adding count += 1 as the last line of the body makes it print 1 to 5 and stop.
- Python refuses to run it and reports a SyntaxError.
After 8 passes of the reading-log loop, pages_read holds 285. At the top of the next pass Python evaluates the condition pages_read < goal with goal at 300. What happens?
Select one.
- The condition is True, so the ninth pass runs.
- The condition is False, so the loop ends at 285.
- The condition is True, but the loop stops at 300.
- The condition is False, so the loop ends at 300.
In the condition count <= 5, the comparison produces True when count is 5.
True or false.
- True
- False
A loop meant to print the numbers 1 to 5 prints only 1 to 4. Which single change makes it print 1 to 5?
count = 1 while count < 5: print(count) count += 1Select one.
- Move print(count) below count += 1.
- Change count += 1 to count += 2.
- Change < to <= in the while line.
- Add break after print(count).
Built with The Course Maker · samples.thecoursemaker.com