CS 0002辅导、辅导Python程序设计

- 首页 >> Database作业
Assignment 10
CS 0002 Section 8
For this assignment you will be writing a single program to solve all the problems in it, which you
should submit on Brightspace.
If you work with another person on your program, please be sure to credit them in the comments in
the header of the program. Remember to comment your program well and to put a header at the
top of the program with your name, the course number and section, the date, and the assignment
number.
Document every function you write with an “input-processing-output” (IPO)-style header. You
should do this for all the functions you write in this class.
You may not use any Python modules in doing this assignment, because there are some
modules, like the “csv” and “pandas” modules, which would make doing it much easier, and the
point of the assignment is for you to learn how to process data from a file using the basic file
operations taught in class.
Problem #1: A Real Estate Database, Redone
Redo the program to construct a real estate database of assignment 8, problem 5, but instead
construct the following nested dictionary.
realEstate = {"Studio Condo": {'sqfootage':400,'bedrooms':0,'price':100000},
"Charming Cottage": {'sqfootage':800,'bedrooms':1,'price':200000},
"Ranch": {'sqfootage':1200,'bedrooms':2,'price':300000},
"Tudor-Style Home": {'sqfootage':2400,'bedrooms':3,'price':500000},
"Georgian-Style Mansion": {'sqfootage':6000,'bedrooms':8,'price':2000000}}

You should implement the same inputs as follows as in the earlier problem (user input is
underlined):
Enter a home description, enter stop to exit: Studio Condo
Enter the square footage: 400
Enter the number of bedrooms: 0
Enter the price: 100000
Enter a home description, enter stop to exit: Charming Cottage
Enter the square footage: 800
Enter the number of bedrooms: 1
Enter the price: 200000
Enter a home description, enter stop to exit: Ranch
Enter the square footage: 1200
Enter the number of bedrooms: 2
Enter the price: 300000
Enter a home description, enter stop to exit: Tudor-Style Home
Enter the square footage: 2400
Enter the number of bedrooms: 3
Enter the price: 500000
Enter a home description, enter stop to exit: Georgian-Style Mansion
Enter the square footage: 6000
Enter the number of bedrooms: 8
Enter the price: 2000000
Enter a home description, enter stop to exit: stop
But when you are done with your inputs, just print the dictionary which should be the same as the
nested dictionary given above (if you give the inputs shown above).
Grading: Five points correct logic, three points correct output, two points comments
Problem #2: Real Estate Database Search, Redone
Redo the real estate database search of assignment 8, problem 5, but instead use the following
nested dictionary as described in problem 1 which you can “wire” at the beginning of your program
(that is, just put the following code there).

realEstate = {"Studio Condo": {'sqfootage':400,'bedrooms':0,'price':100000},
"Charming Cottage": {'sqfootage':800,'bedrooms':1,'price':200000},
"Ranch": {'sqfootage':1200,'bedrooms':2,'price':300000},
"Tudor-Style Home": {'sqfootage':2400,'bedrooms':3,'price':500000},
"Georgian-Style Mansion": {'sqfootage':6000,'bedrooms':8,'price':2000000}}

Grading: Five points correct logic, three points correct output, two points comments
Problem #3: Read the Watch Data into a Nested Dictionary (10 points)
Read the watch data from the assignment 9 into a nested dictionary where the top-level keys are
the line numbers (starting with zero) are the top-level keys and the values are themselves
dictionaries with keys “brand”, “description, “price” and “discount”. Print out the first five records of
this nested dictionary as follows:
0 {'brand': 'fastrack wearables', 'description': 'unisex reflex curv pink strap silicone digital
watch', 'price': 4495, 'discount': 31}
1 {'brand': 'fastrack wearables', 'description': 'unisex 40 mm reflex slay charcoal black dial
silicone smart watch', 'price': 3995, 'discount': 33}
2 {'brand': 'titan', 'description': 'mens 52.50 x 11.70 x 44 mm octane black dial leather analog
watch - 90107kl01', 'price': 3997, 'discount': 50}
3 {'brand': 'timex', 'description': 'men fashion green multifunction strap wrist watch', 'price':
3596, 'discount': 20}
4 {'brand': 'police', 'description': 'mens grey leather multi-function watch - pl15472jsu61',
'price': 7977, 'discount': 40}

If the dictionary you create had only the first three records, it would look like the following:

{0: {'brand': 'fastrack wearables', 'description': 'unisex reflex curv pink strap silicone
digital watch', 'price': 4495, 'discount': 31}, 1: {'brand': 'fastrack wearables', 'description':
'unisex 40 mm reflex slay charcoal black dial silicone smart watch', 'price': 3995, 'discount':
33}, 2: {'brand': 'titan', 'description': 'mens 52.50 x 11.70 x 44 mm octane black dial leather
analog watch - 90107kl01', 'price': 3997, 'discount': 50}}

But put all of the records in the dictionary.
Grading: Five points correct logic, three points correct output, two points comments

Problem #4: Find the Brand Count, Most Expensive Watch, and Average
Watch Price using the New Data Structure (10 points)
Find the brand count, most expensive watch, and average watch price again, but using the new
dictionary-based data structure described above.
Print the brand count by creating and printing out a dictionary where the keys are the brands and
the values are the counts.
Grading: Five points correct logic, three points correct output, two points comments

站长地图