For this assignment you will be creating a Python script to lookup phone numbers in a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For this assignment you will be creating a Python script to lookup phone numbers in a data file given a user-provided last name, or a first and last name. The script should look up all entries in the data file that match the user's request and display them to the screen in the following format (notice that the format includes a comma appended to the last name.) <first name> <last name>, <phone number> The program should repeatedly ask the user for new names to lookup until the user types and empty or blank line, at which point the program should end. For example, the following are test runs of the program with expected output. Enter a last name, or first and last name: smith Drew Smith, 412-555-2121 Elizabeth Smith, 412-555-2121 Enter a last name, or first and last name: drew smith Drew Smith, 412-555-2121 Enter a last name, or first and last name: Data file phones.txt The program should use the file phones.txt as the data file containing the list of known names and numbers. phones.txt has the following format, where the first column is the first name, the second column is the last name, and the last column is the phone number. Pradeep Acharya 301-555-3276 John Brady 321-555-6932 James Chen 256-555-3331 Josh Kelly 424-555-4053 Brady Parker 756-555-3828 Drew Smith 412-555-2121 Elizabeth Smith 412-555-2121 To download phones.txt from within Blackboard, right-click on the file and select "Save link as..." Make sure to save the file to the same folder you plan to write your script in so it will be found when you use the open function to open it (otherwise, you will have to provide a full pathname for the file to the open function.) Requirements: 1. Name your script <your-last-name>_phones.py 2. The input: a. The program should have one prompt that asks the user to enter a last name, or a first and last name (separated by whitespace). It should exit if no names are given and print an error if more than two are given. b. The program should work if the user enters names in uppercase, lowercase, or a mix of case. Since the names in the file phones.txt are of mixed case, for comparisons, you'll want to make use of the string method .lower() to convert both the input strings and those read from the file to lowercase. c. Use the string .split() method on the input to split it into a list of strings, then assign the input to string variables first_name and last_name based on whether the length of the string is one element or two. Also convert the strings to lower case using .lower(). 3. Open phones.txt and loop through each line in the file to see if it matches the provided input. When a match is found, display the output as follows: <first name> <last name>, <phone number> 4. Wrap your code in an infinite loop so the user is repeatedly prompted to enter names for lookup. The program should end when the user enters a blank or empty line. 5. Follow all previously discussed guidelines including proper variable naming, code documentation, and inclusion of a docstring header that includes a description of the program, your name and the date. Test cases: When you're done writing your program you should test it using the input from these examples so you know your program is functioning correctly. Enter a last name, or first and last name: smith Drew Smith, 412-555-2121 Elizabeth Smith, 412-555-2121 Enter a last name, or first and last name: drew smith Drew Smith, 412-555-2121 Enter a last name, or first and last name: brady John Brady, 321-555-6932 Enter a last name, or first and last name: parker Brady Parker, 756-555-3828 Enter a last name, or first and last name: For this assignment you will be creating a Python script to lookup phone numbers in a data file given a user-provided last name, or a first and last name. The script should look up all entries in the data file that match the user's request and display them to the screen in the following format (notice that the format includes a comma appended to the last name.) <first name> <last name>, <phone number> The program should repeatedly ask the user for new names to lookup until the user types and empty or blank line, at which point the program should end. For example, the following are test runs of the program with expected output. Enter a last name, or first and last name: smith Drew Smith, 412-555-2121 Elizabeth Smith, 412-555-2121 Enter a last name, or first and last name: drew smith Drew Smith, 412-555-2121 Enter a last name, or first and last name: Data file phones.txt The program should use the file phones.txt as the data file containing the list of known names and numbers. phones.txt has the following format, where the first column is the first name, the second column is the last name, and the last column is the phone number. Pradeep Acharya 301-555-3276 John Brady 321-555-6932 James Chen 256-555-3331 Josh Kelly 424-555-4053 Brady Parker 756-555-3828 Drew Smith 412-555-2121 Elizabeth Smith 412-555-2121 To download phones.txt from within Blackboard, right-click on the file and select "Save link as..." Make sure to save the file to the same folder you plan to write your script in so it will be found when you use the open function to open it (otherwise, you will have to provide a full pathname for the file to the open function.) Requirements: 1. Name your script <your-last-name>_phones.py 2. The input: a. The program should have one prompt that asks the user to enter a last name, or a first and last name (separated by whitespace). It should exit if no names are given and print an error if more than two are given. b. The program should work if the user enters names in uppercase, lowercase, or a mix of case. Since the names in the file phones.txt are of mixed case, for comparisons, you'll want to make use of the string method .lower() to convert both the input strings and those read from the file to lowercase. c. Use the string .split() method on the input to split it into a list of strings, then assign the input to string variables first_name and last_name based on whether the length of the string is one element or two. Also convert the strings to lower case using .lower(). 3. Open phones.txt and loop through each line in the file to see if it matches the provided input. When a match is found, display the output as follows: <first name> <last name>, <phone number> 4. Wrap your code in an infinite loop so the user is repeatedly prompted to enter names for lookup. The program should end when the user enters a blank or empty line. 5. Follow all previously discussed guidelines including proper variable naming, code documentation, and inclusion of a docstring header that includes a description of the program, your name and the date. Test cases: When you're done writing your program you should test it using the input from these examples so you know your program is functioning correctly. Enter a last name, or first and last name: smith Drew Smith, 412-555-2121 Elizabeth Smith, 412-555-2121 Enter a last name, or first and last name: drew smith Drew Smith, 412-555-2121 Enter a last name, or first and last name: brady John Brady, 321-555-6932 Enter a last name, or first and last name: parker Brady Parker, 756-555-3828 Enter a last name, or first and last name:
Expert Answer:
Answer rating: 100% (QA)
Solution PROGRAMCODE while True ask user to enter a name askName inputEnter a last name or first and ... View the full answer
Related Book For
Data Modeling and Database Design
ISBN: 978-1285085258
2nd edition
Authors: Narayan S. Umanath, Richard W. Scammel
Posted Date:
Students also viewed these programming questions
-
Mason Company provided the following data for this year: Sales Direct labor cost Raw material purchases Selling expenses Administrative expenses Manufacturing overhead applied to work in process...
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
Design a computer desk which may be quickly adjusted in height. This would allow the user to stand and work at the computer for a period of time. Some people will spend more time working in the...
-
A contract is started on 1 January 2015, with an estimated completion date of 31 December 2016. The final contract price is $1,500,000. In the first year, to 31 December 2015: Costs incurred...
-
Use the + / convention to show the direction of expected polarity for each of the following bonds indicated. (a) H3C C1 (b) H3C NH2 (c) H2N H (d) H3C SH (e) H3C MgBr (f) H3C F
-
Let V be the set of all 2 x 2 matrices (a) Is V closed under addition? (b) Is V closed under scalar multiplication? (c) What is the zero vector in the set V? (d) Does every matrix A in V have a...
-
Each of the wires 1 to 3 in Figure P28.39 carries a current perpendicular to the page. The line integrals of the magnetic field around the three Amprian paths shown all have the same positive value....
-
Fill in the blank with the answer. Each answer in the list may be used more than once or not at all. a. Separate and proportionate b. Racketeer Influenced and Corrupt Organization Act (RICO) c....
-
You are planning a 30-day vacation in Malaysia in one year's time. The present charge for a luxury suite plus meals is RM760.00 per day and the RM is presently trading at RM 3.8000/$. Hence the $...
-
Find the figure of a total asset. Note: This problem is for the 2020 tax year. On November 1, 2009, Janet Morton and Kim Wong formed Pet Kingdom, Inc., to sell pets and pet supplies. Pertinent...
-
You are an activist who wants to draw media attention to your claim. Name at least five things suggested in your text that you could do to make your claims appealing to the media. Posting should be...
-
In the following message, Anton tries to convince his boss, the vice president of marketing, that their company could save money by sourcing T-shirts from El Salvador. However, his message could be...
-
Atlantic Southern Airlines (ASA) had an unhappy customer. Casey Segal-Jain flew from Baltimore, Maryland, to Seattle, Washington. The flight stopped briefly at Detroit Metropolitan Airport, where Ms....
-
A well-known financial blogger, Dora Wieland, is doing research for her industry blog In the Know. Specifically, she seeks information about salary and commission information of the star salespeople...
-
Regretfully, we cannot supply you with the cabinet hinge you requested. The manufacturer no longer offers it. A new hinge should work for you, and we are sending it to you. Revise the above sentence...
-
Smithers Ltd, a manufacturer, maintains subsidiary ledgers for creditors and debtors. At 30 June 2016, the total amount owing to the business by trade debtors amounted to $4850 and the total amount...
-
Let X be a random variable that follows a chi-squareddistribution with 17 degrees of freedom. Compute each of thefollowing. HINT: Compute the probabilities using acalculator or Excel. The chi-squared...
-
Evenflow Power Co. is considering a new project that is a little riskier than the current operations of the company. Thus, management has decided to add an additional 1.5% to the company's overall...
-
Consider the instance of the relation SHIRT (Shirt#, Color, Size) where Shirt# is equivalent to a style number (e.g., style number 341 might be a shirt with a button-down collar while style number...
-
Display the entire composition of all subassemblies of the Shovel complete that are either manufactured by Sears or use a component manufactured by Sears?
-
What is the purpose of the cross-referencing design?
-
Figure 4.11 shows the \(v_{x}(t)\) curves for a collision between two identical carts moving not on a low-friction track but rather on a rough surface, so that friction affects their motion. Are the...
-
A small stone is fastened to the top of a standard cart of inertia \(1 \mathrm{~kg}\) to form a combination of unknown inertia \(m_{1}\). A second standard cart is then launched with an initial...
-
(a) A red cart with an initial speed of \(0.35 \mathrm{~m} / \mathrm{s}\) collides with a stationary standard cart \(\left(m_{\mathrm{s}}=1.0 \mathrm{~kg} ight)\). After the collision, the standard...
Study smarter with the SolutionInn App