Day 4.1 Exercise 20 Functions and Files

Here’s my work.
Here’s the link the exercise 20.

Ex20 Code
Ex20 Code
Ex20 Shell
Ex20 Output

Study Drill

1. Write English comments for each line to understand what that line does.
Done for stuff I don’t understand.

2. Each time print_a_line is run, you are passing in a variable current_file. Write out what current_file 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 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 ri File and see if you can figure it out from there. Then try ri “File#seek” to see what seek does.
Ex20 Ri FileSeek.pngI typed it in, and this is what comes out, I have absolutely no clue what that means, however did find the readline command.

5. Research the shorthand notation += and rewrite the script to use += instead.
+=, for example R + 1 is the same as R+=1
We can rewrite it with other operators as well. -=, *= and so on.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s