-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrocery shopping Algorithm.txt
More file actions
84 lines (77 loc) · 2.38 KB
/
Grocery shopping Algorithm.txt
File metadata and controls
84 lines (77 loc) · 2.38 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Grocery shopping purchase algorithm.
# Rage with the machine...
#This algorithm:
#1. takes a grocery item and price.
#2. Evaluates if it is perishable or non perishable.
#3. If non perishable and the item is below the normal price calculates and returns the excess amount to purchase.
#4. If perishable and above normal price returns a do not purchase statement.
#5. If non perishable and above the normal price returns a do not purchase statement.
#6. If perishable and below the normal price returns a purchase statement.
import math
print('Please type the name of the item')
x = input()
x = str(x)
print('Please type the cost of the item in pence per kg')
priceX = input()
priceX = int(priceX)
#List of items
P = ["Eggs","Milk", "White potatoes", "Carrots", "Cherry Tomatoes", "Mushrooms", "Lemons"]
NP = ["Oats", "Pasta", "Baked Beans", "Earl grey", "Orange Juice", "Plain Flour", "Extra Virgin Olive Oil", "Rice",
"Tinned Tomatoes", "Sundried Tomatoes", "Salted Butter", "Dried Yeast", "Chicken Breast", "Marmite","Cheese", "Green Olives"]
#Price look up
Pdict = {
"Eggs": 120,
"Milk": 52,
"White potatoes": 67,
"Carrots": 40,
"Cherry tomatoes": 200,
"Mushrooms": 396,
"Lemons": 0,
}
NPdict = {
"Oats": 75,
"Pasta": 140,
"Baked Beans": 100,
"Earl Grey": 100,
"Orange Juice": 81,
"Plain flour": 30,
"Chicken Breast": 579,
"Extra Virgin Olive Oil": 0,
"Rice": 0,
"Tinned Tomatoes": 141,
"Sundried Tomatoes": 614,
"Salted Butter": 592,
"Dried Yeast": 1551,
"Marmite": 0,
"Cheese": 442,
"Green Olives": 376,
}
#Price lookup comapared to normal expense
NPdict2 = {
"Oats": 52,
"Pasta": 52,
"Baked Beans": 208,
"Earl Grey": 78,
"Orange Juice": 12,
"Plain flour": 52,
"Chicken Breast": 4,
"Extra Virgin Olive Oil": 52,
"Rice": 104,
"Tinned Tomatoes": 208,
"Sundried Tomatoes": 12,
"Salted Butter": 52,
"Dried Yeast": 26,
"Marmite": 52,
"Cheese": 26,
"Green Olives": 52,
}
if x in P and ((priceX-Pdict[x]) > 0 ) :
print("Buy Substitute or Delay Purchase")
elif x in NP and ((priceX-NPdict[x]) > 0):
print("Delay")
elif x in NP and (priceX-NPdict[x]) <= 0 :
y = (NPdict[x]/priceX)
r = y**3
print("Buy", int(r), "times usual amount Maximum", NPdict2[x])
elif x in P and ((priceX-Pdict[x]) <= 0 ) :
print("Buy item as usual ")