Questions: For Loops

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

What sequence of integers does range(1, 10, 3) produce?

A1, 4, 7, 10
B1, 4, 7
C0, 3, 6, 9
D1, 3, 6, 9
Question 2 Multiple Choice

A programmer writes: `for item in my_list: if item < 0: my_list.remove(item)`. What problem can this cause?

AA syntax error — you cannot call remove() on a list during iteration
BThe loop variable 'item' becomes undefined after the first removal
CElements may be silently skipped — removing an item shifts subsequent elements to earlier positions, causing the loop's internal index to jump past the next element
DThe condition item < 0 is only evaluated once, before the loop begins, so only the first negative item is removed
Question 3 True / False

range(5) produces the sequence 1, 2, 3, 4, 5.

TTrue
FFalse
Question 4 True / False

A Python for loop can iterate directly over a string, binding the loop variable to each character in sequence.

TTrue
FFalse
Question 5 Short Answer

Describe a situation where a while loop is clearly more appropriate than a for loop, and explain why.

Think about your answer, then reveal below.