首页 > > 详细

辅导CS 0002、辅导Python,C++程序

Assignment 9
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: Read in a CSV (Comma-Separated Values) File (10 points)
For this problem, you need to read in the “watches.csv” file which contains data about some
watches sold in India. This file was distributed with this assignment. The first few lines are as
follows:
Name,Details,New price,Discount
fastrack wearables,unisex reflex curv pink strap silicone digital watch,4495,31
fastrack wearables,unisex 40 mm reflex slay charcoal black dial silicone smart watch,3995,33
titan,mens 52.50 x 11.70 x 44 mm octane black dial leather analog watch - 90107kl01,3997,50
timex,men fashion green multifunction strap wrist watch,3596,20
police,mens grey leather multi-function watch - pl15472jsu61,7977,40

The first item on each line is the watch brand, the second is the details of the watch (description),
followed by the new price, and then the discount as a percentage. Each of these are separated by
commas (hence the name “comma-separated values”).
Read in this file into an array of lines using the readlines() method. This will give you a list of strings,
one per line. Then convert the data into a list of lists, each of which has four items representing the
four items on each line. The first two items should be strings and the second two integers. Print out
the first five items of this list. You should get the following:
[['fastrack wearables', 'unisex reflex curv pink strap silicone digital watch', 4495, 31],
['fastrack wearables', 'unisex 40 mm reflex slay charcoal black dial silicone smart watch', 3995,
33], ['titan', 'mens 52.50 x 11.70 x 44 mm octane black dial leather analog watch - 90107kl01',
3997, 50], ['timex', 'men fashion green multifunction strap wrist watch', 3596, 20], ['police',
'mens grey leather multi-function watch - pl15472jsu61', 7977, 40]]

Make sure you don’t include the header line in this list.
Grading: Five points correct logic, three points correct output, two points comments

Problem #2: Find the Brands (10 points)
Find and print all a list of all the unique brands in the data. In the five records above, there are four
brands, “fastrack wearables,” “titan,” “timex,” and “police.” But there are more than these in the
whole file.
Grading: Five points correct logic, three points correct output, two points comments
Problem #3: Find the Brand Count (10 points)
For each of the brands found in problem 2, find how many watches there are in the database. Print
a list of these counts in the same order as the list produced for problem #2. What brand has the
most watches and what is the number? Print out the answers to each of these questions.
Grading: Five points correct logic, three points correct output, two points comments
Problem #4: Find the Most Expensive Watch (10 points)
What watch in the database has the highest price (which is in rupees)? Print out the list of four
items associated with this watch. What is this highest price?
Grading: Five points correct logic, three points correct output, two points comments
Problem #5: Find the Average Price of the Watches (10 points)
Find the average price (in rupees) of all the watches in the database. Print it.
Grading: Five points correct logic, three points correct output, two points comments

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!