Congratulations! You're about to get a new car! The simplest yet most complex machine ever made by mankind. You can now comfortably get to school, get family around, or better yet, brag to all your friends that you have your driver's license. There's a problem. All of the overwhelming choices of cars! You just went through the stress of going through driver's ed, and now you have to actually choose a car. If there were just a car recommendation program that wouldn't give me the generic "Toyota Corolla" as a first car.
Well, now you could! Carmendation is a Python program I made as a portfolio project for myself; however, it's becoming a lot neater than I had initially anticipated. As a car enthusiast myself, I love to make sure that when recommending cars to people, I don't just recommend generic cars that promise reliability and fuel efficiency. You just got that taste of sweet driving freedom and getting such a boring car that you see every day just won't cut it. You're gonna need something that you can look back at and say, "Yeah, I made the right choice!"
Carmendation has a dataset of 150 cars! All from different countries, among the most popular for their engineering, from the cute Mazda Miata to the loud Volkswagen GTI up to the businessman's car, a BMW 5 Series. Each car is scored based on how many preferences are input by the user, and a linear search algorithm goes through all of those 150 cars to provide 5 of the best cars. Of course, if it seems overwhelming to the user, he/she doesn't need to answer all of the questions; however, it's a much more personalized experience when the algorithm actually has factors to test against.
How the scoring works
The score is based on many factors such as price range, reliability, drivetrain, body type, country of origin, and your desired tags! The algorithm then fetches all the cars with relatively the same preferences you input and provides the 5 highest-scoring cars from highest to lowest scoring out the 5
def recommend(wanted_tags, coo, body_type, drivetrain, fuel_type, reliability, max_price):
results = []
for car in CARS:
# Filter out cars that don't meet the basic criteria
# None means the user has no preference for that filter
if max_price is not None and int(car[PRICE]) > max_price:
continue
if reliability is not None and int(car[RELIABILITY]) < reliability:
continue
# Add a score based on how many tags and other criteria match
# (an empty list means no preference, otherwise the car must match one of the choices)
score = sum(1 for t in wanted_tags if t in car[TAGS_IDX])
score += 1 if reliability is not None else 0
score += 1 if max_price is not None else 0
score += 1 if car[COUNTRY] in coo else 0
score += 1 if car[BODY] in body_type else 0
score += 1 if car[DRIVE] in drivetrain else 0
score += 1 if car[FUEL] in fuel_type else 0
# Add the car to the results if it has a positive score
if score > 0:
results.append((score, car))
# Sort based on highest scoring car, provide 5 close competitors
results.sort(reverse=True, key=lambda r: r[0])
return results[:5]
A problem I ran into
The hardest moment was definitely making the program support more than one preference in any of the categories; however, I fixed it by keeping the array that contained the preferences as a raw array, and then formatted it by stripping and making sure to separate each prefernce by a comma

What I'd improve next
As soon as I learn how to make web/app interfaces, I would give this program exactly that, so that the terminal output would look a lot more organized and easy on the eyes
So, why don't you test it yourself on my GitHub? Just download the code and test a car recommendation site built by a car enthusiast!

Top comments (0)