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
.
.. literalinclude:: ex/ex20.txt :language: console
- Go through and write English comments for each line to understand what's going on.
- Each time
print_a_line
is run you are passing in a variablecurrent_line
. Write out whatcurrent_line
is equal to on each function call, and trace how it becomesline_count
inprint_a_line
. - Find each place a function is used, and go check its
def
to make sure that you are giving it the right arguments. - Research online what the
seek
function forfile
does. Trypydoc file
and see if you can figure it out from there. - Research the shorthand notation
+=
and rewrite the script to use that.