500error
[Cos Pro 1급, python] 1차 1번 : 음식전문점 운영 본문
반응형
문제
배달음식 전문점 운영을 위해 다음과 같이 DeliveryStore 인터페이스와 PizzaStore, Food 클래스를 작성했습니다.

* DeliveryStore :
* DeliveryStore는 배달 음식점의 인터페이스입니다.
* 배달 음식점은 set_order_list와 get_total_price 함수를 구현해야 합니다.
* set_order_list 함수는 주문 메뉴의 리스트를 매개변수로 받아 저장합니다.
* get_total_price 함수는 주문받은 음식 가격의 총합을 return 합니다.
* DeliveryStore는 배달 음식점의 인터페이스입니다.
* 배달 음식점은 set_order_list와 get_total_price 함수를 구현해야 합니다.
* set_order_list 함수는 주문 메뉴의 리스트를 매개변수로 받아 저장합니다.
* get_total_price 함수는 주문받은 음식 가격의 총합을 return 합니다.
* Food :
* Food는 음식을 나타내는 클래스입니다.
* 음식은 이름(name)과 가격(price)으로 구성되어있습니다.
* Food는 음식을 나타내는 클래스입니다.
* 음식은 이름(name)과 가격(price)으로 구성되어있습니다.
* PizzaStore
* PizzaStore는 피자 배달 전문점을 나타내는 클래스이며 DeliveryStore 인터페이스를 구현합니다.
* menu_list는 피자 배달 전문점에서 주문 할 수 있는 음식의 리스트를 저장합니다.
* order_list는 주문 받은 음식들의 이름을 저장합니다.
* set_order_list 함수는 주문 메뉴를 받아 order_list에 저장합니다.
* get_total_price 함수는 order_list에 들어있는 음식 가격의 총합을 return 합니다.
* PizzaStore는 피자 배달 전문점을 나타내는 클래스이며 DeliveryStore 인터페이스를 구현합니다.
* menu_list는 피자 배달 전문점에서 주문 할 수 있는 음식의 리스트를 저장합니다.
* order_list는 주문 받은 음식들의 이름을 저장합니다.
* set_order_list 함수는 주문 메뉴를 받아 order_list에 저장합니다.
* get_total_price 함수는 order_list에 들어있는 음식 가격의 총합을 return 합니다.
주문 메뉴가 들어있는 리스트 order_list가 매개변수로 주어질 때, 주문한 메뉴의 전체 가격을 return 하도록 solution 함수를 작성하려고 합니다. 위의 클래스 구조를 참고하여 주어진 코드의 빈칸을 적절히 채워 전체 코드를 완성해주세요.
코드
from abc import *
class DeliveryStore(metaclass=ABCMeta):
@abstractmethod
def set_order_list(self, order_list):
pass
@abstractmethod
def get_total_price(self):
pass
class Food:
def __init__(self, name, price):
self.name = name
self.price = price
class PizzaStore(DeliveryStore):
def __init__(self):
menu_names = ["Cheese", "Potato", "Shrimp", "Pineapple", "Meatball"]
menu_prices = [11100, 12600, 13300, 21000, 19500];
self.menu_list = []
for i in range(5):
self.menu_list.append(Food(menu_names[i], menu_prices[i]))
self.order_list = []
def set_order_list(self, order_list):
for order in order_list:
self.order_list.append(order)
def get_total_price(self):
total_price = 0
for order in self.order_list:
for menu in self.menu_list:
if order == menu.name:
total_price += menu.price
return total_price
def solution(order_list):
delivery_store = PizzaStore()
delivery_store.set_order_list(order_list)
total_price = delivery_store.get_total_price()
return total_price
반응형
'알고리즘 > 파이썬' 카테고리의 다른 글
[Cos Pro 1급, Python] 1차 3번 : 계산기 by 문자열 (0) | 2024.02.26 |
---|---|
[Cos Pro 1급, Python] 1차 2번 : 해밍 거리 구하기 (1) | 2024.02.26 |
[COS Pro 2급, Python] 6차 10번 : 사과 박스 무게의 불량 검사 (1) | 2024.01.12 |
[COS Pro 2급, Python] 6차 9번 : 난 양말색이 달라도 잘 신는 착한 어린이 (0) | 2024.01.12 |
[COS Pro 2급, Python] 6차 8번 : 주어진 수와 뒤집은 수의 차구하기 (0) | 2024.01.12 |
Comments