Omniadisce

Computational physics 2.5: Adding up as you go

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.

13 steps ยท about 20 min

By the end you can

  • Keep a running total in a loop: start before, add inside, print after
  • Write total += x for total = total + x
  • Count the times something happens, with count += 1
  • Put an if inside a loop, with its body pushed in twice
  • Fix a total that is reset or added outside the loop

Who it is for: After lesson 2.4: you can write a for loop with range.

The steps

  1. Adding up in a loop
  2. A running total
  3. 1 + 2 + ... + 100
  4. += : add to
  5. Add to
  6. A bike ride
  7. Where each line goes
  8. Back to zero
  9. Galileo's rolling ball
  10. Counting
  11. Eight spaces
  12. Count the slow seconds
  13. In your own words

Discussion 0 comments

Log in to join the discussion.

× Enlarged view