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
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.) , 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 _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: , 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:
Step by Step Solution
3.32 Rating (149 Votes )
There are 3 Steps involved in it
Step: 1
Solution PROGRAMCODE while True ask user to enter a name askName inputEnter a last name or first and ...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started