I am doing a question:
We’d like to host these wine reviews on our website, but a rating system ranging from 80 to 100 points is too hard to understand - we’d like to translate them into simple star ratings. A score of 95 or higher counts as 3 stars, a score of at least 85 but less than 95 is 2 stars. Any other score is 1 star.
Also, the Canadian Vintners Association bought a lot of ads on the site, so any wines from Canada should automatically get 3 stars, regardless of points.
Write a function that takes a score and a country as parameters and returns the respective star value. Display the country, variety, points, and star rating.
The dataset contains the following columns:
Currently, i could only get the following:
if dfwine['country'] == 'Canada':
rating = 3
rating = 3
elif points <95 and points >= 85:
rating = 2
rating = 1
But I am stuck with what to do afterwards, could anyone please help?
Thank you very much in advance.
Do you have a link to the CC lesson?
Thank you very much for replying.
Sorry I do not have a link but its similar to the following questions in the website:
Its Exercise 7 but my work requires me to “Write a function that takes a score and a country as parameters and returns the respective star value. Display the country, variety, points, and star rating.”
Is this for a school test?
What is the result of what you’ve written so far? What’s your error message?
It’s not for a school test, it is an assignment.
Sorry i could not get any answer when i run it as i am not sure how to continue and my codes are incomplete.
Nothing is printing b/c you haven’t passed any arguments or called the function.
I don’t have access to that csv file. But, I did write out a function with points & country as the parameters like so:
def star_rating(points, country):
So, let’s think about this a different way for starters.
Pretend there’s no pandas df. How would you write a function with those two parameters that would work when passing in any country or points arguments when the function is called?
How would that logic look in the function (considering that
if the country is Canada and no matter what their points value is they will always get 3 stars, and, 95 or higher counts as 3 stars, a score of at least 85 but less than 95 is 2 stars. Any other score is 1 star)?
Try that, write it out if it helps. (I’m also assuming that this exercise builds on the previous ones, so the clues are there.)
Thank you for your time & reply.
It’s alright, I have managed to solve it with some samples that I could find.