Assignment 20 — problem solving
Due Wednesday March 31
Program common_commodities.py
- Produce a program that gives the cost of individually-supplied, user-specified commodities.
- The user will indicate with empty query that there are no more queries to process. If the user supplies an unknown commodity, then a warning should be issued.
- The commodity along with their current prices can be found at CSV web file.
- For your information, the commodities given in the web file are currently
cocoa cotton heating oil platinum sugar
coffee crude oil natural gas silver unleaded gas
copper gold orange juice soybeans wheat
corn
- The location of the web file is
http://www.cs.virginia.edu/~cs1112/datasets/csv/spot-prices.csv
- The contents of the web file do not necessarily reflect current pricing in mercantile markets.
- The contents of the web file will change during our testing of your effort.
Suggested algorithm
- Get contents of web file as a csv data sheet
- Create a dictionary for mapping commodities to cost
- Loop until user has signaled no more queries.
- Get next query
- Clean up query
- Examine query -- there are three possibilities
- Is empty — done looking for queries
- Is in dictionary — need to process request
- Is not in dictionary — need to flag that request is unknown.
Sample runs
Enter commodity: natural gas$2.54 (million BTUs)
Enter commodity: unleaded gas
$1.89 (gallons
Enter commodity:
Enter commodity: copper$4.08 (lbs)
Enter commodity: platinum
$1182.10 (troy ounces)
Enter commodity: sea shells
pricing unknown
Enter commodity: crude oil
$68.78 (barrels)
Enter commodity:
Enter commodity: orange juice$1.12 (lbs)
Enter commodity:
Enter commodity:
🦆 © 2022 Jim Cohoon | Resources from previous semesters are available. |