Repeating Actions with Loops - Lesson 3

Questions

  • How can I do the same operations on many different values?

Objectives

  • Explain what a for loop does.
  • Correctly write for loops to repeat simple calculations.
  • Trace changes to a loop variable as the loop runs.
  • Trace changes to other variables as they are updated by a for loop.

Lecture



Alternate video link.


Jupyter Notebook File

Please use the Jupyter notebook named "03RepeatingActionsWithLoops.ipynb" for this lesson. If you haven't downloaded them already, you may find them here.

Key Points

  • Use for variable in sequence to process the elements of a sequence one at a time.
  • The body of a for loop must be indented.
  • Use len(thing) to determine the length of something that contains other values.