simeonshopov

Pizza Delivery

Jun 3rd, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. class PizzaDelivery:
  2.     def __init__(self, name: str, price: float, ingredients: dict):
  3.         self.ordered = False
  4.         self.name = name
  5.         self.price = price
  6.         self.ingredients = ingredients
  7.  
  8.     def add_extra(self, ingredient: str, quantity: int, ingredient_price: float):
  9.         if self.ordered:
  10.             return f"Pizza {self.name} already prepared and we can't make any changes!"
  11.         else:
  12.             if ingredient not in self.ingredients:
  13.                 self.ingredients[ingredient] = quantity
  14.                 self.price += ingredient_price * quantity
  15.             else:
  16.                 self.ingredients[ingredient] += quantity
  17.                 self.price += ingredient_price * quantity
  18.  
  19.     def remove_ingredient(self, ingredient: str, quantity: int, ingredient_price: float):
  20.         if self.ordered:
  21.             return f"Pizza {self.name} already prepared and we can't make any changes!"
  22.         else:
  23.             if ingredient not in self.ingredients:
  24.                 return f'Wrong ingredient selected! We do not use {ingredient} in {self.name}!'
  25.             if quantity > self.ingredients[ingredient]:
  26.                 return f'Please check again the desired quantity of {ingredient}!'
  27.             else:
  28.                 self.ingredients[ingredient] -= quantity
  29.                 self.price -= ingredient_price * quantity
  30.  
  31.     def pizza_ordered(self):
  32.         if self.ordered:
  33.             return f"Pizza {self.name} already prepared and we can't make any changes!"
  34.         self.ordered = True
  35.         return f"You've ordered pizza {self.name} prepared with" \
  36.                f" {', '.join([f'{k}: {v}' for k, v in self.ingredients.items()])} and the price will be {self.price}lv"
Add Comment
Please, Sign In to add comment