Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.58 KB | None | 0 0
  1. class Pizza:
  2.  
  3.     def __init__(self, size='Small', toppings=[]):
  4.         self.__size = size
  5.         self.__topping_list = toppings
  6.  
  7.     def __str__(self):
  8.         string = 'Pizza: ' + self.__size + ', Toppings:'
  9.         for topping in self.get_topping_list():
  10.             string = string + ' ' + topping
  11.         return string
  12.  
  13.     def get_size(self):
  14.         return self.__size
  15.  
  16.     def set_size(self, size):
  17.         self.__size = size
  18.  
  19.     def get_topping_list(self):
  20.         return self.__topping_list
  21.  
  22.     def set_topping_list(self, toppings):
  23.         self.__topping_list = toppings
  24.  
  25.     def add_topping(self, topping):
  26.         self.__topping_list.append(topping)
  27.  
  28.     def get_cost(self):
  29.         costs = [10, 12, 14]
  30.         final_cost = 0
  31.         if self.get_size() == 'Small':
  32.             final_cost += costs[0]
  33.         elif self.get_size() == 'Medium':
  34.             final_cost += costs[1]
  35.         elif self.get_size() == 'Large':
  36.             final_cost += costs[2]
  37.  
  38.         final_cost += (len(self.get_topping_list()) * 2)
  39.         return final_cost
  40.  
  41. pizza_list = []
  42. pizza_list.append(Pizza('Small', ['Cheese', 'Bacon', 'Egg', 'Pineapple']))
  43. pizza_list.append(Pizza('Medium', ['Peppironi', 'Ham', 'Sausage', 'Tomato', 'Onion']))
  44. pizza_list.append(Pizza('Large', ['Cheese', 'Cheese', 'More Cheese']))
  45.  
  46. highest_cost = 0
  47. highest_pizza = ''
  48.  
  49. for pizzas in pizza_list:
  50.     cost = pizzas.get_cost()
  51.     if cost > highest_cost:
  52.         highest_cost = cost
  53.         highest_pizza = pizzas
  54.  
  55. print("Most expensive pizza (", highest_pizza, ") is: $", cost, '.', sep='')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement