TDT4109/Exercise 1/10 - Bakekurs/10-a.py

31 lines
801 B
Python
Raw Normal View History

2020-08-31 23:16:07 +02:00
from common import inputTypeCheck
2020-08-26 14:47:36 +02:00
class recipe:
def __init__(self, ingredients, standardPortions):
self.ingredients = ingredients
self.standardPortions = standardPortions
def getIngredients(self, portions):
ratio = portions / self.standardPortions
for ingredient in self.ingredients:
print(f'{ingredient}: {self.ingredients[ingredient]*ratio}')
cookies = recipe(
ingredients={
'sukker(g)': 400,
'smør(g)': 320,
'sjokolade(g)': 500,
'egg': 2,
'hvetemel(g)': 460
},
standardPortions=48,
)
cookieNumber = inputTypeCheck(
message = 'Hvor mange cookies ønsker du å bake? ',
type = float,
errorMessage = 'Beklager, det du skrev inn er ikke et tall. Prøv igjen\n'
)
2020-08-26 14:47:36 +02:00
print('Antall cookies:', cookieNumber)
cookies.getIngredients(cookieNumber)