-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecipeBook.py
48 lines (32 loc) · 1.62 KB
/
RecipeBook.py
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
class Item:
def __init__(self, ingredient, carbs, meassurement): #maybe just leave at self
self.ingredient = ingredient
self.carbs = int(carbs)
self.meassurement = int(meassurement)
self.total = int(carbs) * (int(meassurement)/100)
def main():
print ("Hello. Welcome to the recipe book for Type 1 Diabetics! \nYou can use this programme to caluclate the total carbs in recipes and how much insulin you should take for a portion." )
carbs_to_insulin = input("What is your carbs to insulin ratio? \n(i.e. How many grams of carbs per 1 unit of insulin you take.)" )
ingredientList = []
i=0
while i == 0 or input("Do you have another product? Y/n").lower()[0] == "y":
i+=1
recipeDict = {
"item" : input("What is the next item?"),
"carbs per 100g" : input("How many carbs per 100g?"),
"meassurement" : input("How many grams of this item are you using?")
}
# validate input
print (recipeDict)
# create item from input
newItem = Item(recipeDict.get("item"), recipeDict.get("carbs per 100g"), recipeDict.get("meassurement"))
# add item to list /// consider case where item may already exist
ingredientList.append(newItem)
# print(ingredientList)
sum = 0
for ingredient in ingredientList:
sum += ingredient.total
print(f"Total carbs in meal: {sum}")
insulin_required = float(sum) / float(carbs_to_insulin)
print(f"You must take {insulin_required}g of insulin. \nBon Apetite!")
main()