Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PizzaDelivery:
- def __init__(self, name, price, ingredients):
- self.name = name
- self.price = price
- self.ingredients = ingredients
- self.ordered = False
- def add_extra(self, ingredient: str, quantity: int, price_per_quantity: float):
- if self.ordered:
- return f"Pizza {self.name} already prepared, and we can't make any changes!"
- if ingredient not in self.ingredients:
- self.ingredients[ingredient] = 0
- self.ingredients[ingredient] += quantity
- self.price += price_per_quantity * quantity
- def remove_ingredient(self, ingredient: str, quantity: int, price_per_quantity: float):
- if self.ordered:
- return f"Pizza {self.name} already prepared, and we can't make any changes!"
- if ingredient not in self.ingredients:
- return f"Wrong ingredient selected! We do not use {ingredient} in {self.name}!"
- elif self.ingredients[ingredient] < quantity:
- return f"Please check again the desired quantity of {ingredient}!"
- self.ingredients[ingredient] -= quantity
- self.price -= price_per_quantity * quantity
- def make_order(self):
- self.ordered = True
- result = f"You've ordered pizza {self.name} prepared with "
- # sorted_ingredients = sorted(self.ingredients.items(), key=lambda x: x[1])
- result += ', '.join([f'{ingredient}: {quantity}' for ingredient, quantity in self.ingredients.items()])
- result += f" and the price will be {self.price}lv."
- return result
- margarita = PizzaDelivery('Margarita', 11, {'cheese': 2, 'tomatoes': 1})
- margarita.add_extra('mozzarella', 1, 0.5)
- margarita.add_extra('cheese', 1, 1)
- margarita.remove_ingredient('cheese', 1, 1)
- print(margarita.remove_ingredient('bacon', 1, 2.5))
- print(margarita.remove_ingredient('tomatoes', 2, 0.5))
- margarita.remove_ingredient('cheese', 2, 1)
- print(margarita.make_order())
- print(margarita.add_extra('cheese', 1, 1))
Advertisement
Add Comment
Please, Sign In to add comment