Omniadisce

Computational physics 2.2: if: only when it's true

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

  • Write an if with a condition and a colon
  • Say which lines an if controls: its indented body
  • Indent a line by four spaces, with the Tab key
  • Read and fix an IndentationError
  • Spot a line that should be in the body but isn't

Who it is for: After lesson 2.1: you can write comparisons such as speed > limit.

The steps

  1. Fined or not?
  2. if
  3. Run it
  4. Under the limit
  5. Which line does it control?
  6. The body: four spaces in
  7. Write the body
  8. Forgot the spaces? IndentationError
  9. Reading the error
  10. Fix the bug
  11. Outside the body, it always runs
  12. The innocent driver
  13. Why the spaces matter

Discussion 0 comments

Log in to join the discussion.

× Enlarged view