Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 1.11 KB

ex20.rst

File metadata and controls

33 lines (22 loc) · 1.11 KB

Exercise 20: Functions And Files

Remember your checklist for functions, then do this exercise paying close attention to how functions and files can work together to make useful stuff.

.. literalinclude:: ex/ex20.py
    :linenos:

Pay close attention to how we pass in the current line number each time we run print_a_line.

What You Should See

.. literalinclude:: ex/ex20.txt
    :language: console



Extra Credit

  1. Go through and write English comments for each line to understand what's going on.
  2. Each time print_a_line is run you are passing in a variable current_line. Write out what current_line is equal to on each function call, and trace how it becomes line_count in print_a_line.
  3. Find each place a function is used, and go check its def to make sure that you are giving it the right arguments.
  4. Research online what the seek function for file does. Try pydoc file and see if you can figure it out from there.
  5. Research the shorthand notation += and rewrite the script to use that.