simeonshopov

Pizza Delivery

Jun 8th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. #!usr/local/bin/python3.8
  2. # -*- coding: utf-8 -*import
  3.  
  4.  
  5. class PizzaDelivery:
  6.     def __init__(self, name: str, price: float, ingredients: dict):
  7.         self.ordered = False
  8.         self.name = name
  9.         self.price = price
  10.         self.ingredients = ingredients
  11.  
  12.     def add_extra(self, ingredient: str, quantity: int, ingredient_price: float):
  13.         if not self.ordered:
  14.             if ingredient not in self.ingredients:
  15.                 self.ingredients[ingredient] = 0
  16.             self.ingredients[ingredient] += quantity
  17.             self.price += ingredient_price * quantity
  18.         else:
  19.             return f"Pizza {self.name} already prepared and we can't make any changes!"
  20.  
  21.     def remove_ingredient(self, ingredient: str, quantity: int, ingredient_price: float):
  22.         if not self.ordered:
  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.             self.ingredients[ingredient] -= quantity
  28.             self.price -= ingredient_price * quantity
  29.         else:
  30.             return f"Pizza {self.name} already prepared and we can't make any changes!"
  31.  
  32.     def pizza_ordered(self):
  33.         self.ordered = True
  34.         return f"You've ordered pizza {self.name} prepared with" \
  35.                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