Advertisement
malixds_

udemy_hmwrk

Oct 3rd, 2022
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. class Beverage:
  2.     prices = {"Strawberries": 1.5, "Banana": 0.5, "Mango": 2.5,
  3.               "Blueberries": 1, "Raspberries": 1, "Apple": 1.75,
  4.               "Pineapple": 3.5}
  5.  
  6.     def __init__(self, ingredients):
  7.         self.ingredients = ingredients
  8.  
  9.     def get_cost(self):
  10.         cost_prices = 0
  11.         for i in self.ingredients:
  12.             for j in Beverage.prices:
  13.                 if i == j:
  14.                     cost_prices += Beverage.prices[i]
  15.         str(cost_prices)
  16.         return "$"+"{0:4.2f}".format(cost_prices)
  17.  
  18.     def get_price(self):
  19.         full_price = 0
  20.         for i in self.ingredients:
  21.             for j in Beverage.prices:
  22.                 if i == j:
  23.                     full_price += Beverage.prices[i]
  24.         full_price *= 2.5
  25.         str(full_price)
  26.         return "$"+"{0:4.2f}".format(full_price)
  27.  
  28.     def get_name(self):
  29.         self.ingredients.sort()
  30.         new_ingredients = []
  31.         for i in self.ingredients:
  32.             a = i.replace('ies', 'y')
  33.             new_ingredients.append(a)
  34.         if len(self.ingredients) == 1:
  35.             a = self.ingredients[0].replace('ies', 'y')
  36.             new_ingredients.append(a)
  37.             return new_ingredients[0] + ' Smoothie'
  38.         elif len(self.ingredients) > 1:
  39.             for i in self.ingredients:
  40.                 str_a = ' '.join(new_ingredients)
  41.         return str_a + " Fusion"
  42.  
  43.  
  44. s1 = Beverage(["Banana"])
  45. s1.ingredients
  46. s1.get_cost()
  47. s1.get_price()
  48. s1.get_name()
  49. s2 = Beverage(["Raspberries", "Strawberries", "Blueberries"])
  50. s2.ingredients
  51. s2.get_cost()
  52. s2.get_price()
  53. s2.get_name()
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement