Usually, people learning to program are given exercises where a function name,
parameters, and return type are decided for them, and the function is fairly
straightforward. Presumably, most of you have had this
experience. The next step is for you to choose to
write functions yourself, figuring out what data they need and what they should
return. In the next set of videos, we'll lead you
through this process, giving you tips on how we make these choices.
And along the way, as an added bonus, you'll get more practice with
dictionaries, lists, and files. The problem we'll be tackling is a
restaurant recommendation system. Here is a list of restaurants, including
the name of the restaurant, the percentage of people who liked the restaurant, the
price range of the restaurant, and the cuisines of food that the restaurant
serves. $1 means that a meal doesn't cost much
money. $4 indicates a very expensive restaurant.
There are a lot of websites that give recommendations for restaurants based on
the price range that someone is searching for, or the kinds of food that they want.
We're going to do something similar with a smaller file, that is just going to be on
our own computer, but it will give you an ideal of how these websites do the job
they do. The program we're going to design will
make recommendations to a user based on this data.
We'll tell you a bit about the main function, that this task is complex and
helper functions will make writing the main function much easier.
Here's the problem, write a function that takes the Open Restaurant file, a price
range, and a list of cuisine. It's going to return a list of restaurants
and their ratings sorted by ratings from highest to lowest.
Let's do an example starting with even fewer restaurants so there isn't that much
data to keep track of. Let's say, you're interested in cheap
Chinese or Thai. Well, the cheap restaurants are Queen
Street Cafe, Dumplings R Us, and Deep Fried Everything.
Of those, Deep Fried Everything serves Pub Food and not Thai or Chinese.
That leaves Queen Street Cafe and Dumplings R Us.
The higher rated one is Queen Street Cafe, and so we'll want to return a list, like
this. In the next video, we'll explore how we're
going to keep track of all this data in Python and in the video after that, we'll
figure out how to break the problem down into a series of subproblems.