Omniadisce

Computational physics 3.1: Your own function

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 25 min

By the end you can

  • Say what def, the parameters, the body and return each do
  • Call a function with your own numbers, in the right order
  • Write the body of a function, indented, with return
  • Read an IndentationError and fix it

Who it is for: Anyone who has done units 1 and 2 of this course (print, variables, if, for loops), and physics lessons 1.3 and 2.2 (converting units, speed).

The steps

  1. A first guess
  2. A formula with a name
  3. The parts of a function
  4. Which part gives the answer back?
  5. Run it
  6. Calling with your own numbers
  7. Call it yourself
  8. Order matters
  9. Writing the body
  10. Write the body
  11. An indentation error
  12. Your turn: falling speed
  13. Why bother?

Discussion 0 comments

Log in to join the discussion.

× Enlarged view