
In this assignment, you will write a Python program to process an input file.
Download the file minor5.tsv. Each row of this file contains a data record separated by a single
tab. The fields are: state, street address, city, zip code.
Your need to write a python program that allows users to search for entries using the city
or zip code.
(a) Write a python function called load_records that given a filename as input, opens the file
and reads in the data. Each data record should be represented as a tuple of strings. The
function should return two objects: A dictionary mapping zip codes to lists of such tuples
and a dictionary mapping cities to sets of zip codes.
(b) Write a python program that first reads in the data file once (using the function from part
(a)), and then asks the user repeatedly to enter a zip code or a city name (in a while loop
until the user types “quit”). For each request, the program prints all data records for this
city or zip code. If city names are ambiguous (duplicated city names), all entries should be
printed. If no records can be found, you need to print according information such as :
No records found in this town.
or
No records found in this zip code.
(c) The format for printed out information should be:
Street address
Town, state, zipcode
minor5.tsv
Arkansas |
705 E. Union Ave |
Wynne |
72396 |
California |
Main Street |
Redding |
96099 |
California |
Calabasas & Mullholland Drive |
Tarzana |
91356 |
Colorado |
Buffalo Street |
Dillon |
80435 |
Colorado |
802 W. Drake Rd |
Fort Collins |
80526 |
New Mexico |
6th & University |
Las Vegas |
98765 |
New Mexico |
corner of bookout and central avenue |
tularosa |
88352 |
New York |
112th Madison Avenue |
NY |
10029 |
New York |
W. 57th St. & Ninth Ave at Balsley Park |
NY |
10037 |
SAMPLE OUTPUT:
hz0099@cse02:~/3600/python$ python minor5.py
Enter input:10037
W. 57th St. & Ninth Ave at Balsley Park
NY, New York, 10037
Enter input:88352
corner of bookout and central avenue
tularosa, New Mexico, 88352
Enter input:Wynne
705 E. Union Ave
Wynne, Arkansas, 72396
Enter input:Fort Collins
802 W. Drake Rd
Fort Collins, Colorado, 80526
Enter input:denton
No records found in this town.
Enter input:76207
No records found in this zip code.
Enter input:NY
W. 57th St. & Ninth Ave at Balsley Park
NY, New York, 10037
112th Madison Avenue
NY, New York, 10029
Enter input:quit
hz0099@cse02:~/3600/python$

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

- each line in the input file will represent a record of data. There will be 10 lines, thus 10 records. Each record (line) will consist of 3 space separated fields: a name (1 word as a string), and age (as an integer), and a wage (as a float). Write a C program that: takes an input file name from the command line; opens that file if possible; declares a C struct with three variables; these will have data types that correspond to the data types read from the file (i.e. string, int, float); declares an array of C structs (i.e. the same struct type declared in point c); reads a record from the file and stores the values read into the appropriate struct variable at the appropriate array index (for that record); continues reading each record into a struct (as in point 1e), and stores each struct containing the 3 values into the array of structs declared in point d; closes the file when all records have been read. should print an error message in the event that the file cannot be…arrow_forwardThe international Olympics Committee has asked you to write a program to process their data and determine the medal winners for the pairs figure skating. You will be given a file named Pairs.txt.This file contains the data for each pair of skaters. The data consists of each skater’s name, their country and the score from each of eight judges on the technical aspects and on the performance aspects. A typical record in the file would be as follows: SmithJonesAustralia5.0 4.9 5.1 5.2 5.0 5.1 5.2 4.84.3 4.7 4.8 4.9 4.6 4.8 4.9 4.5 LennonMurrayEngland2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.83.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8GustoPetitotItalia4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.85.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8LahaiePetitFrance1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.85.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8BilodeauBernardCanada2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.84.1 4.2 4.3 4.8 4.9 4.6 4.0 4.5LahorePedroMexico3.2 3.1 3.8 3.9 3.0 3.6 3.9 3.35.9 5.8 5.8 5.8 5.9 5.6 5.0 5.5MaliakKolikovRussia4.2 4.1 4.8 4.9 4.0 4.6 4.9 4.31.9 1.8 1.8 1.8…arrow_forwarda. Implement the following function in Python. Do not copy the docstring into answer. def get_record (fh, n): 111111 Find the n-th record in a comma-delimited sequential file. Records are numbered starting with 0. Use: record = get_record (fh, n) Parameters: fh - file to search (file - open for reading) n - the number of the record to return (int > 0) Returns: #1 #111 record - a list of the fields of the n-th record if it exists, an empty list otherwise (list) Paragraph b- Write a testing program to test the function from part a. The program should ask the user for a fil V 8⁰ BI Uv Αγ + v MacBarrow_forward
- You are given a file called “std” and composed of “Number, Name, Address” fields. (You can define the type of fields by yourself) Write an algorithm that makes “insert, delete, update and retrieve”, processes on the records in the file. “Number” field is the key of each record. Here is the template of report: Steps Actions 1 Name of the report and date 2 Author of report Literature review Your contribution 5 Explanation algorithm and sub algorithms 6 Summary Future advice References ps: write a algorithm not a programarrow_forwardSolve in Python Include Screenshots of Input and Output For this lab, you will write a program that creates and edits a test file called users.txtYour program should implement the following functions: add_user – Accepts a username as an argument and adds it to the file update_user – Accepts an old username and a new username as separatearguments and replaces any instance of that the old username with the newusername in the file. remove_user – Accepts a username as an argument and removes the userfrom the fileUse the following code to test your program:add_user(“bob”)add_user(“joe”)add_user(“ann”)add_user(“mike”)update_user(“joe”, “jo”)remove_user(“ann”)Your final file should look like:bobjomikeYour submission should include your source code (.py file) and either yourfinal text file or a screenshot of it.arrow_forwardwrite in c++Write a program that would allow the user to interact with a part of the IMDB movie database. Each movie has a unique ID, name, release date, and user rating. You're given a file containing this information (see movies.txt in "Additional files" section). The first 4 rows of this file correspond to the first movie, then after an empty line 4 rows contain information about the second movie and so forth. Format of these fields: ID is an integer Name is a string that can contain spaces Release date is a string in yyyy/mm/dd format Rating is a fractional number The number of movies is not provided and does not need to be computed. But the file can't contain more than 100 movies. Then, it should offer the user a menu with the following options: Display movies sorted by id Display movies sorted by release date, then rating Lookup a release date given a name Lookup a movie by id Quit the Program The program should perform the selected operation and then re-display the menu. For…arrow_forward
- Plz solve assignment 5 by using assignment 8, use c programming and plz don't use any other libraries other than stdio . harrow_forwardWrite a function named repeat_words that takes two string parameters: 1. in_file: the name of an input file that exists before repeat_words is called 2. out_file: the name of an output file that repeat_words creates Assume that the input file is in the current working directory and write the output file to that directory. For each line of the input file, the function repeat_words should write to the output file all of the words that appear more than once on that line. Each word should be lower cased and stripped of leading and trailing punctuation. Each repeated word on a line should be written to the corresponding line of the output file only once, regardless of the number of times the word is repeated. For example, if the following is the content of the file catInTheHat.txt: Too wet to go out and too cold to play ball. So we sat in the house. We did nothing at all. So all we could do was to Sit! Sit! Sit! Sit! The following function call: inF = 'catInTheHat.txt' outF =…arrow_forwardWrite the code segments based on the given descriptions: Declare a file pointer called input. Open a file called location.txt for reading using this pointer. If the file is not available, display “File does not exist.”. The content of the text file location.txt is as shown below. It includes the location, latitude and longitude values. FILE location.txt CONTENTS <Location> <Latitude> <Longitude> UTM 1.5523763 103.63322 KLCC 3.153889 101.71333 UM 3.1185 101.665 UMS 6.0367 116.1186 UNIMAS 1.465174 110.4270601 Ask the user to enter a location. Check if the user’s location can be found in the text file. If found, display the location, latitude and longitude as shown below. SAMPLE OUTPUT Enter a location: UM Location : UM Latitude : 3.1185 Longitude : 101.6650 Otherwise display “Sorry, location could not be found”. SAMPLE OUTPUT Enter a location : MMU Sorry, location could not be foundarrow_forward
- Please help with my C++Specifications • For the view and delete commands, display an error message if the user enters an invalid contact number. • Define a structure to store the data for each contact. • When you start the program, it should read the contacts from the tab-delimited text file and store them in a vector of contact objects. •When reading data from the text file, you can read all text up to the next tab by adding a tab character ('\t') as the third argument of the getline() function. •When you add or delete a contact, the change should be saved to the text file immediately. That way, no changes are lost, even if the program crashes laterarrow_forwardTrying to write C++ program: 1. Write a program to do the following: 2. Create an array to hold up to 20 integers. 3. Create a data file or download attached text file (twenty_numbers.txt) thatcontains UP TO 20 integers.4. Request the input and output file names from the user. Open the filesbeing sure to check the file state.5. Request from the user HOW MANY numbers to read from the data file,up to twenty. Request the number until the user enters 20 or less, but not lessthan 0. The user enters the number of integers to read. The integers are storedin the file and are to be read from the file.6. Write a function that reads from the opened data file: the numberof integers the user wants to read, and store the numbers in the array. For example, if the user wants to read 13 numbers, read 13 of the 20 that may be in the file.7. Write a function that writes to the opened output file AND THECONSOLE, the numbers stored in the array.8. NO GLOBAL variables are to be used. The input and output…arrow_forwardWrite a program in C++ that allows the user to create files of random data. They should be offered a menu of possibilities: 1) create random Whole number data file 2) create random Decimal number data file 3) create random Character data file 4) Quit programarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





