Due:Friday, December 7, 2012 at 11:55PM
Points: 100
Please turn in your answers for the homework assignment on SmartSite, under Homework #5 in Assignments. Turn in your programs answers for the extra credit under Extra Credit #5 there.
The file “dict.txt”, available in the Text folder of the Resources area on Smartsite, is a list of words, one per line. You are to ask the user for a word, and then print all the word in that file that are anagrams of the word the user enters. Your program is to terminate when the user types control-d (end of file).
The input may include blanks and other non-letters, so you should treat the line of input as what to look for. Also, treat upper and lower case the same.
The rules for output are:
Here is some sample output:
Your word? aboard↵ The anagrams for aboard are aborad and abroad Your word? welcome↵ There are no anagrams for welcome Your word? phe↵ The word phe is not in the dictionary Your word? hep↵ There are no anagrams for hep Your word? salt↵ The anagrams for salt are last and slat Your word? alst↵ The word alst is not in the dictionary Your word? gear↵ The anagrams for gear are ager, agre, gare and rage Your word? control-d↵
Please call your program “anagram.py”.
Hint: Store the words in a dictionary. Try sorting their characters into order and using that as a key. Then you can store words with the same characters as a list, accessed by the key produced by sorting their characters.
Remember to hand this in under Extra Credit #5, not under Homework #5!
Zipf’s law describes a relationship between the ranks and frequencies of words in natural languages. It predicts that the frequency f of the word with rank r is
Write a program that prompts the user for a file name, reads text from that file, counts word frequencies, and plots log f against log r using the turtle package. Check whether this plot is a straight line. If it is, can you estimate s?
Please use the file “alice.txt” for this problem. It is available in the Text folder of the Resources area on Smartsite.
Please call your program “zipf.py”.
ECS 10, Basic Concepts of Computing Fall Quarter 2012 |