Assignment 2
Acronym Generator
due Sunday January 28
Task
The goal of this assignment is to write a program that can take a string of arbitrary length as an argument and return an acronym representing the input string. For example, given the input "United States of America", the program should return USA. Given "University of California at San Diego", it should return UCSD.
Additional information
ACRONYM n. A word formed from the initial letters of a name, such as WAC for Women's Army Corps, or by combining initial letters or parts of a series of words, such as RADAR for RAdio Detection And Ranging. (American Heritage Dictionary of the English Language)
SNAFU is a famous acronym. Do you know its origin?
Details
Part 1
Some input strings will contain numbers or other characters that are not wanted. For instance The "university" of California at San Diego is UCSD, not "U"CSD, or even worse, "CSD.
Write a function that can take a string and return a new string from which non-letter characters have been removed. (Hint: The string module contains a variable called string.letters that contains all letters. You would do well to explore the string module looking for other useful functions.) As an example, your finished function should be able to take the string "/my/ house" and return "my house".
For full credit, the definition of this function must be removeJunk(mystring), and it must return a string.
sample test: removeJunk('Hello, world!') == 'Hello world'
Part 2
Write a function that finds the individual words in your cleaned-up string. (Hint: You may use the 'split()' function from the string module in your function, or write your own function to do this.)
For full credit, the definition of this function must be stringToWords(mystring), and it must return a list of strings.
sample test: stringToWords('Hello world') == ['Hello', 'world']
Part 3
Write a function that removes the words "of", "at", "the", and "and" from a list of words.
For full credit, the definition of this function must be removeUnwantedWords(list), and it must return a list of strings.
sample test: removeUnwantedWords(['the', 'of', 'at', 'and', 'hello']) == ['hello']
Part 4
Use the functions you have already written to compose a function that takes a string as an argument and outputs an acronym. You MUST use all the functions written in Parts 1-3 for full credit. Output the acronym in uppercase letters.
For full credit, this function must be defined as generateAcronym(mystring), and it must also return a string.
sample test: generateAcronym('United States of America') == 'USA'
Final notes
What happens if someone tries generateAcronym(5)? It's not clear what the output should be, but at least make sure that your program doesn't crash!
You will find this assignment MUCH easier if you test each function you write as soon as you finish witting it, rather than waiting until you put them all together in Part 4.
Assignment submission details
- Place all of your code in a file called acronym_<UCID>.py (where <UCID> corresponds to your UCSD e-mail address). For instance jsmith@ucsd.edu would turn in acronym_jsmith.py
- At the start of the file, write your name in comments. Also write a short explaintaion of how your program works, highlighting any assumptions you made about the problem, experiments you ran to show that the code worked, and anything else you want to communicate about the assignment.
- Attach this file to an e-mail message addressed to cg8w1@icogsci1.ucsd.edu with the subject "<UCID> acronym.py"
- Send the email no later than Sunday, January 28 at 11:59 pm.
Hints/Recommendations
- Make sure you read Chapters 6, 7, and 8!
- See http://www.devshed.com/c/a/Python/String-Manipulation/ for some examples of string manipulation
- Accomplish earlier steps before attempting later ones!
- Make sure the code you submit is well documented, since this will make it more likely the graders will understand what you were trying to do.
- If you get stumped before you finish the entire assignment:
- document your accomplishments.
- describe the problem that stopped you, what you tried, what confused you, etc.