Question
Download the file markets.txt which contains geographic information for over 7000 farmers markets in the US (source http://explore.data.gov/d/wfna-38eyLinks to an external site.). Each line contains
Download the file markets.txt which contains geographic information for over 7000 farmers markets in the US (source http://explore.data.gov/d/wfna-38eyLinks to an external site.). Each line contains information about a one farmers market. Data fields are separated by a single "#" symbol. The fields are (in this order): state, market name, street address, city, zip code.
Download the skeleton code problem2.py.
a) Write a class Market that represents a farmers market. The Market class should have the following attributes:
state (a string)
market_name (a string)
street_address (a string)
zip code (an int)
city (a string)
You can ignore the longitude and latitude entries.
b) Add a __str__ method that returns information about the famers market in human readable form (use string formatting). For example
Columbia University Greenmarket E. Side of Broadway between 114th & 115th Streets New York, New York 10027
c) Write a function read_markets(filename), that reads in the market data from a file. The function should return a dictionary mapping zip codes to lists of Market objects (there can be multiple markets in the same zip code).
d) Write a main program that first calls read_markets to read in markets.txt. Then, your program should prompt the user to type in a zip code. It should then print out the string representation for each market in that zip code, or "No farmers markets in your zip code." if none were found.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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