Omniadisce

Computational physics 3.5: Loops over a list, and the mean

Lesson Beginner

Join free to take this lesson

Anyone can look around, but taking a lesson needs a free account. With one, your answers are checked step by step and your progress is saved, so you can stop and pick up where you left off on any device.

12 steps ยท about 25 min

By the end you can

  • Loop over the items of a list with for
  • Add up a list's items as you go
  • Work out the mean as total รท len
  • Use sum(list) / len(list)
  • Build a list with append in a loop

Who it is for: Anyone who has done lesson 3.4, and physics lesson 1.5 (the mean of repeated measurements).

The steps

  1. A loop over a list
  2. Run it
  3. How many lines?
  4. Adding up as you go
  5. Add them up
  6. The mean
  7. The mean time
  8. A shortcut: sum
  9. Which line prints the mean?
  10. The mean in one line
  11. Build a list in a loop
  12. The loop and the shortcut

Discussion 0 comments

Log in to join the discussion.

× Enlarged view