In python! please be thorough and read question carefully :) if possible, give explanation for code We’re...

70.2K

Verified Solution

Question

Programming

In python! please be thorough and read question carefully :) ifpossible, give explanation for code

We’re going to create a class which stores information aboutproduct ratings on a website such as Amazon. The ratings are allnumbers between 1 and 5 and represent a number of “stars” that thecustomer gives to the product. We will store this information as alist of integers which is maintained inside the class StarRatings.You will be asked to write the following:

1) A constructor which takes and stores the product name.

2) A function “giveRating” which takes an integer between 1 and5 and stores it. If the number is outside that range, it should notstore the number.

3) A function “calcAverage” which returns the average of theratings. This can be done in linear time

4) A function getStarCount which returns a five element listcontaining the count of the number of ratings for each star. Forexample if the ratings were 5,5,2,3,1, and 1, this function wouldreturn [2,1,1,0,2] (2x 1 stars, 1x 2 stars, 1x 3 stars, 0x 4 stars,2x 5 stars)

5) Sometimes a mistake is made and the site posts the sameproduct twice. If that’s the case we will need to “add” the twostar ratings together to produce a larger list with the result.write a function so that two StarRatings class objects can be“added” together using the + operator

6) If the product manufacturer pays us, we can adjust the starratings by an amount. Allow for “multiplication” of every starrating by a constant amount. For example if the StarRatings Objectis sr, allow for “sr1.5”. However, the star ratings must ALWAYSremain integers. In that example all 1 star reviews would become 2stars (11.5 = 1.5, rounded to integer would be 2), 2 starreviews would be 3(2*1.5 = 3) etc.

Answer & Explanation Solved by verified expert
3.9 Ratings (391 Votes)
Program CodeScreenshotSampleoutputThe screenshots are attached below for referencePlease follow them for proper indentation and outputProgram tocopyimport mathclass StarRatingsdef    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students