CS105: Computer Programming: PYTHON Project 02 Assigned on Monday, Sept. 17, 2007 Due on Monday, Sept. 24 at 11:59PM ============= 1. Objectives ============= In this project, we implement a python script that manages (i.e., look up, add, delete, and so on) a directory. For simplicity, we assume a directory having names and corresponding phone numbers. This project contains some contents that we have not learned, but will cover on this Friday. So, please start doing this project in advance and ask some questions in the class. ============== 2. Description ============== We will implement all the following requirements: (2.1) The script will be called "directory.py" (2.2) The script (i.e., directory.py) will contain a dictionary called "directory". Each record consists of name and phone number. (2.3) It will contain the following functionalities: printMenu(), getMenuChoice(), printDirectory(directory), addMember(directory), deleteMember(directory), and searchMember(directory) (Details of each subroutine will be described in sequel) (2.4) The script will be run from the commandline as below: > ./directory.py - Menu will be printed out on the screen. - User will choose a number to proceed. - The function corresponding to user's choice will be run. (2.5) From this project, all script should be well documented. ============================== 3. Grading criteria and policy ============================== Here are the details of each subroutine in the menu. NOTE: Your script will be graded based on how well the required functionality is fulfilled. Therefore, please follow the description as much as possible to get full credits. NOTE: you are reqested to use "raw_input()" to get user inputs for the time being and later you will be requested to use "input()" to get user inputs. ------------------------------- (3.1) "printMenu()" (10 points) ------------------------------- It basically shows the following menu: (HINT: we can use either multiple "print" statements, each of which print out one line or use "print" with """ (or ''')) Please make your choice: 1. List all 2. Add one 3. Delete one 4. Search one 5. End ----------------------------------- (3.2) "getMenuChoice()" (10 points) ----------------------------------- It gives the following line, takes user's choice, and returns it. Your choice (1-5): --------------------------------------------- (3.3) "printDirectory(directory)" (20 points) --------------------------------------------- It prints out all directory contents as follows: Print Name and Phone: Directory contains XX record(s). Name: AAA Phone: 512-aaa-aaaa Name: BBB Phone: 513-bbb-bbbb ... ---------------------------------------- (3.4) "addMember(directory)" (20 points) ---------------------------------------- Add Name and Phone: Name: AAA Phone: 512-aaa-aaaa if the given name (i.e., AAA for this example) is already in the directory, print out the following message and overwrite the contents. AAA is already in the directory, so it is now overwritten. If the given name is not in the directory, print out the following message and store the contents in the directory. AAA is not in the directory, so it is newly stored. ------------------------------------------- (3.5) "deleteMember(directory)" (20 points) ------------------------------------------- Delete Name and Phone: Name: BBB Phone: 512-bbb-bbbb if the given name (i.e., BBB for this example) is already in the directory, print out the following message and delete the contents. BBB is already in the directory, so it is now deleted. If the given name is not in the directory, print out the following message and do nothing. BBB is not in the directory, so nothing happens. ------------------------------------------- (3.6) "searchMember(directory)" (20 points) ------------------------------------------- Search Name and Phone: Name: CCC if the given name (i.e., CCC for this example) is already in the directory, print out the message and the corresponding contents as follows. CCC is in the directory. Name: CCC Phone: 512-ccc-cccc If the given name is not in the directory, print out the following message and do nothing. CCC is not in the directory. --------------------------------- (3.7) "printEnding()" (10 points) --------------------------------- It prints out the following message and end the script running. Thanks for using the directory. > ----------------------------------------------------------------------- (3.8) do proper documentation for your module and functions (10 points) ----------------------------------------------------------------------- You can get more information about docstrings from the following URL: http://www.python.org/dev/peps/pep-0257/ -------------------------------------------------------- (3.9) change of "raw_input()" into "input()" (30 points) -------------------------------------------------------- First, check out the following URL and make sure you understand the difference between "raw_input()" and "input()". http://www.thinkfree.com/view.tfo?file=7eFijPGjD50%3dtfo Make another copy of your script, "directory.py". For example, > cp directory.py directoryModified.py then, you have a new copy called "directoryModified.py". Now, we start modifing the contents of "directoryModified.py" as follows: change all occurrences of "raw_input()" into "input()" Run the code, choose "2. Add one", and answer the following questions: (NOTE that describe your answers in a file called "answer02.txt" turn it in with your code, see details at the end of this file) (1) 5 points Is it running properly with the same input that you used for "directory.py"? (2) 5 points Is it possible to run "directoryModified.py" without any problems? (3) 10 points What is difference between "raw_input()" and "input()"? (4) 10 points If it is not working properly, how do you resolve the problem? If possible, you can modify the content of "directoryModified.py" (however make sure you still use "input()".) (HINT) Choose "2. Add one" with the following inputs for each script (You may not proceed with some of inputs because of error): AAA 'AAA' "AAA" 1+2 '1+2' "1+2" Then, choose "1. List all" to check out the added values. ============================== 4. Grading criteria and policy ============================== Please make sure to include the followings at the header of the code. In summary, each script should contain AT LEAST the followings: -------------------------------------------------------------------- # Project: 02 # Description: Telephone Directory # Program: directory.py (or directoryModified.py) # Input: NONE # Output: NONE # Usage: ./directory.py (or ./directoryModified.py) # Name: Your name # UT EID: Your EID # Comments (or README): # Describe what you with to grader to know. # e.g., What did you like/dislike about this project? # What was the most challenging in this project? # etc. printMenu() ......... getMenuChoice() ......... printDirectory() ......... addMember(directory) ......... deleteMember(directory) ......... searchMember(directory) ......... printEnding() ......... if __name__ == '__main__': ......... ------------------------------------------------------------ ================== 5. Running example ================== The followings are expected upon running your script: -------------------------------------------------------------- > ./directory.py # ./directoryModified.py Please make your choice: 1. List all 2. Add one 3. Delete one 4. Search one 5. End Your choice (1-5): 1 Print Name and Phone: Directory contains 0 record(s). Please make your choice: 1. List all 2. Add one 3. Delete one 4. Search one 5. End Your choice (1-5): 2 Add Name and Phone Name: AAA Phone: 512-aaa-aaaa AAA is not in the directory, so it is newly stored. Please make your choice: 1. List all 2. Add one 3. Delete one 4. Search one 5. End Your choice (1-5): 2 Add Name and Phone Name: BBB Phone: bbb-bbbb BBB is not in the directory, so it is newly stored. Please make your choice: 1. List all 2. Add one 3. Delete one 4. Search one 5. End Your choice (1-5): 2 Add Name and Phone Name: CCC Phone: ccc CCC is not in the directory, so it is newly stored. Please make your choice: 1. List all 2. Add one 3. Delete one 4. Search one 5. End Your choice (1-5): 1 Print Name and Phone: Directory contains 3 record(s). Name: AAA Phone: 512-aaa-aaaa Name: BBB Phone: bbb-bbbb Name: CCC Phone: ccc Please make your choice: 1. List all 2. Add one 3. Delete one 4. Search one 5. End Your choice (1-5): 3 Delete Name and Phone Name: bbb bbb is not in the directory, so nothing happens. Please make your choice: 1. List all 2. Add one one 3. Delete one one 4. Search one one 5. End Your choice (1-5): 3 Delete Name and Phone Name: BBB BBB is already in the directory, so it is now deleted. Please make your choice: 1. List all 2. Add one 3. Delete one 4. Search one 5. End Your choice (1-5): 4 Search Name and Phone Name: ccc ccc is not in the directory. Please make your choice: 1. List all 2. Add one 3. Delete one 4. Search one 5. End Your choice (1-5): 4 Search Name and Phone Name: CCC CCC is in the directory. Name: CCC Phone: ccc Please make your choice: 1. List all 2. Add one 3. Delete one 4. Search one 5. End Your choice (1-5): 5 Thanks for using the directory. > ----------------------------------------------------------- ======= 6. NOTE ======= This project is worth a total of 150 points. We'll discuss details about the project in the class. Submit one answer file, "answer02.txt" and two script files, "directory.py" and "directoryModified.py", as follows: > turnin --submit hyukcho project02 answer02.txt directory.py directoryModified.py Good luck!