Homework #5

Due: February 27, 2012Points: 100

As for all earlier assignments, please put refinements for all your programs into one file called “refinements.txt” or “refinements.pdf”, and error journal entries for all your programs into one file called “errors.txt” or “errors.pdf”.

In the example outputs, what your program outputs is in typewriter font, what the user types is in italicized typewriter font, and the user typing “enter” or “return” is represented by the character “↵”. You don’t need to change the font, use italics, or show the “↵” in your output.

  1. (50 points) This program asks you to modify the linsearch.py program we discussed in class to read words from a file. Please take that program and add the following command to it. When the user types f file, the contents of file is appended to the list. The file will contain one word per line.

    For example, if the file “xxx.txt” contains the words

    we
    people
    these
    united
    states
    an example execution of the program would be:
    what do I do (s word, a word, f file, p)? f xxx.txt
    Added word 'we' to list
    Added word 'people' to list
    Added word 'these' to list
    Added word 'united' to list
    Added word 'states' to list
    added words to wordlist
    what do I do (s word, a word, f file, p)? p
     1. when
     2. in
     3. the
     4. course
     5. of
     6. human
     7. events
     8. we
     9. people
    10. these
    11. united
    12. states
    what do I do (s word, a word, f file, p)? s states
    'states' is word number 12
    what do I do (s word, a word, f file, p)? ↵

    Submit: Please turn in your program in the file “ls1.py”.

  2. (50 points) Write a program that asks the user for a URL, reads from that URL, and prints the contents. When it prints each line, it also prepends the line number, with the largest line number left-justified and all other line numbers with units’ digit lined up with that of the largest line number, then outputs a tab, and then prints the line. Here is sample input and output (as there are 115 lines in the output, it is truncated):
    What URL should I fetch? http://www.rfc-editor.org/rfc/rfc1149.txt
      1.
      2.
      3.
      4.
      5.
      6.
      7. Network Working Group                                        D. Waitzman
      8. Request for Comments: 1149                                       BBN STC
      9.                                                             1 April 1990
     10.
     11.
     12.    A Standard for the Transmission of IP Datagrams on Avian Carriers
     13.
    . . . skipping lines 14 through 112 . . .
    113.
    114. Waitzman                                                        [Page 2]
    115.
    Submit: Please turn in your program in the file “urlread.py”.

A PDF version is available here.
ECS 10, Basic Concepts of Computing
Winter Quarter 2012