Development Artist

[COS Pro 1급, Python] 1차 1번 : 음식전문점 운영 본문

Algorithm/COS

[COS Pro 1급, Python] 1차 1번 : 음식전문점 운영

JMcunst 2022. 2. 24. 17:00
728x90
반응형

문제 유형

빈칸

난이도

easy

Note 

1. 파이썬에서 Class와 def를 어떻게 정의하는지.

2. self의 용도가 무엇인지.

 

Code

# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
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

order_list = ["Cheese", "Pineapple", "Meatball"]
ret = solution(order_list)

print("solution 함수의 반환 값은", ret, "입니다.")

 

※ 가끔 코드 중 print(~)가 있습니다. 정리 못한 점 죄송합니다.

728x90
반응형
Comments