-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnlineShoppingAlgorithm.py
More file actions
35 lines (28 loc) · 1.29 KB
/
OnlineShoppingAlgorithm.py
File metadata and controls
35 lines (28 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
products = int(input("Number of products you want to choose between: "))
ratings = []
reviews = []
prices = []
for i in range(1, products + 1):
rating = float(input(f"Enter the rating of product {i}: "))
review = float(input(f"Number of reviews of product {i}: "))
price = float(input(f"Price of product {i}: "))
ratings.append(rating)
reviews.append(review)
prices.append(price)
avgratall = sum(ratings) / products
avgrevall = sum(reviews) / products
avgpriall = sum(prices) / products
weights = []
for i in range(1, products + 1):
weight = (((avgratall * reviews[i - 1]) + (ratings[i - 1] * avgrevall)) / (reviews[i - 1]
+ avgrevall)) * (avgpriall + sum(prices)) / (prices[i - 1] + sum(prices))
weights.append(weight)
maxweirat = max(weights)
bestpronum = weights.index(maxweirat)
answer = input("Do you want to see the weighted rating of all products (y/n)?")
if answer == "y":
for i in range(1, products + 1):
print(f"The weighted rating of product {i} is: ", (((avgratall * reviews[i - 1]) + (ratings[i - 1] * avgrevall)) / (reviews[i - 1]
+ avgrevall)) * (avgpriall + sum(prices)) / (prices[i - 1] + sum(prices)))
else:
print("Product", bestpronum + 1, "has the highest weighted rating of", maxweirat)