Assignment — problem solving
Never formally assigned
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/commodities.csv
- The contents of the web file will change during our testing of your effort.
Suggested algorithm
- Get contents of web file as dictionary that maps commodities to cost
- Determine for the query responses whether a query is valid, empty (whitespace), or invalid
- If valid, determine its cost using the commodity dictionary and print result.
- If only whitespace, query processing is over
- If invalid, print an error message.
Sample runs
Enter commodity: natural gas$2.88 (million BTUs)
Enter commodity: unleaded gas
$1.32 (gallons)
Enter commodity:
Enter commodity: copper$3.03 (lbs)
Enter commodity: platinum
$932.00 (troy ounces)
Enter commodity: sea shells
pricing unknown
Enter commodity: crude oil
$50.53 (barrels)
Enter commodity:
Enter commodity: orange juice$1.52 (lbs)
Enter commodity:
Enter commodity:
Warning: fopen(/l/cs1112/public_html/defs/htm/181-trailer): Failed to open stream: No such file or directory in /l/cs1112/public_html/defs/php/read.php on line 5
Unable to open file!