CPSC120 Lab 10

Data Analysis

  1. Difference

    Create a program in a file called diff.py that prompts the user for two file names. The program should compare the two files line-by-line up to the number of lines in the smaller file. If two corresponding lines in the file are different, the program should print the line number. If the files are the same, it should not print anything.

  2. The Great Firewall of China

    The Chinese government censors the Internet for its citizens by blocking all content from web sites that contain information that subverts the government such as a news story on the Tienanmen Square protests. In fact this web site may be blocked because this web page mentions Tienanmen Square. Write a program for a Western news company that does not want to be blocked by the Chinese firewall. The program should be in a file called censor.py and should prompt the user for the name of an html document. The program should overwrite the specified html file with the contents of the original file except all occurrences of the text “Tienanmen Square” should be replaced with “CENSORED”. The program should ignore case, but preserve punctuation. The program should not use the string replace function.

    You should test your program on a simple text file first. You can test it on an html file like this one by downloading the html as a file in Firefox by right-clicking on a web page and choosing “Save Page As…” In the file dialog that appears, choose the directory containing your Python code and choose “Web Page, HTML only” as the save type. After the file is modified by your program you can open the HTML file in Firefox to verify that it has been properly censored.

  3. Scrabble

    Create a program in a file called scrabble.py that prompts the user for an integer between 1 and 23. If the user’s input is not a number or if it is not a number between 1 and 23, the program should prompt the user again until the user enters valid input.

    After getting valid input from the user, the program should search a text file that contains 1 word per line for a word that is the length specified by the user and has the highest scrabble value of any word in the file of the specified length. The scrabble value of a word is calculated by summing the value of each letter in the word according to the following table.

    Letter a b c d e f g h i j k l m n o p q r s t u v w x y z
    Points 1 3 3 2 1 4 2 4 1 8 5 1 3 1 1 3 10 1 1 1 1 4 4 8 4 10

    Use list comprehensions to find a words with the highest scrabble value. You should test your program on a simple dictionary file. If it is working correctly you can test it on the Linux dictionary file, /usr/share/dict/words.

Submission

Submit a zip file of your code on the course Inquire site that uses your last names as the file name.