Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Pizza:
- def __init__(self, size='Small', toppings=[]):
- self.__size = size
- self.__topping_list = toppings
- def __str__(self):
- string = 'Pizza: ' + self.__size + ', Toppings:'
- for topping in self.get_topping_list():
- string = string + ' ' + topping
- return string
- def get_size(self):
- return self.__size
- def set_size(self, size):
- self.__size = size
- def get_topping_list(self):
- return self.__topping_list
- def set_topping_list(self, toppings):
- self.__topping_list = toppings
- def add_topping(self, topping):
- self.__topping_list.append(topping)
- def get_cost(self):
- costs = [10, 12, 14]
- final_cost = 0
- if self.get_size() == 'Small':
- final_cost += costs[0]
- elif self.get_size() == 'Medium':
- final_cost += costs[1]
- elif self.get_size() == 'Large':
- final_cost += costs[2]
- final_cost += (len(self.get_topping_list()) * 2)
- return final_cost
- pizza_list = []
- pizza_list.append(Pizza('Small', ['Cheese', 'Bacon', 'Egg', 'Pineapple']))
- pizza_list.append(Pizza('Medium', ['Peppironi', 'Ham', 'Sausage', 'Tomato', 'Onion']))
- pizza_list.append(Pizza('Large', ['Cheese', 'Cheese', 'More Cheese']))
- highest_cost = 0
- highest_pizza = ''
- for pizzas in pizza_list:
- cost = pizzas.get_cost()
- if cost > highest_cost:
- highest_cost = cost
- highest_pizza = pizzas
- print("Most expensive pizza (", highest_pizza, ") is: $", cost, '.', sep='')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement