Check your understanding of the primer: what a for loop is made of, what loop patterns are, and why you might compose loops into functions.

Question 1

Which of the following is NOT a major element of a Python for loop?

Select one answer, then check.

  • Correct. The primer names three major components: the iteration variable, the iteration list, and the body of the loop. "Nested cycle" is not one of them.
  • Not quite. The iteration variable is one of the three major components, representing each element of the list one at a time.
  • Not quite. The iteration list is one of the three major components: it is the data the loop iterates over.
  • Not quite. The body is one of the three major components: the code that runs once for each element.

Question 2

Which of the following is NOT true about Python for loop patterns?

Select one answer, then check.

  • Correct, this is the false statement. A loop pattern is a reusable code template that you copy and paste into your own program and fill in the blanks; it is not a language feature like a function or an if statement.
  • Not quite, this is true. Every pattern has blanks for the original list, an iteration variable, and some resulting value.
  • Not quite, this is true. Count, Filter, and Find are three of the patterns listed in the primer.
  • Not quite, this is true. That is exactly what the Minimum and Maximum patterns do.

Question 3

Which of the following is a disadvantage of composing loops in functions?

Select one answer, then check.

  • Correct. The primer names this as the trade-off ("although this increases the number of functions you have to write and test") before listing the advantages.
  • Not quite. The primer lists this as the first advantage, not a disadvantage.
  • Not quite. The primer lists this as the second advantage, not a disadvantage.
  • Not quite. The primer lists this as the third advantage, not a disadvantage.