본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 92

반응형

Q>

You are the owner of a cafe where 3 chefs work: a JapaneseCook, RussianCook and ItalianCook.

(당신은 3 명의 요리사가 일하는 카페의 주인 인 JapaneseCook, RussianCook 및 ItalianCook입니다.)

Each of them can prepare the national food and beverage:

(그들 각각은 국가 음식과 음료를 준비 할 수 있습니다 : )


- JapaneseCook: Sushi and Tea;(초밥과 차; )
- RussianCook: Dumplings and Compote;( 만두와 콩트)
- ItalianCook: Pizza and Juice.(피자와 주스.


Your task is to create 3 different subclasses (one for each chef) which are the children of an AbstractCook and have these methods:

(당신의 임무는 AbstractCook의 자식이며 다음과 같은 세 가지 하위 클래스 (각 요리사마다 하나씩)를 만드는 것입니다.)


- add_food(food_amount, food_price), which add to the client's order the value of the food which he had chosen;

  (고객의 주문에 그가 선택한 음식의 가치를 더합니다.)
- add_drink(drink_amount, drink_price), which add to the client's order the value of the drink which he had chosen;

  (클라이언트의 주문에 그가 선택한 음료의 가치를 더합니다.

- total(), which returns a string like: 'Foods: 150, Drinks: 50, Total: 200', and for the each chef instead of the Foods and Drinks will be the national food and drink that he’s used.

  (200'과 같은 문자열을 반환하며, Foods and Drinks 대신 각 요리사가 사용하는 국가 식품 및 음료입니다)

 

Every client can choose only one chef. In this mission the Abstract Factory design pattern could help.

(모든 고객은 한 명의 요리사 만 선택할 수 있습니다. 이 임무에서 Abstract Factory 디자인 패턴이 도움이 될 수 있습니다.

 

Example:

client_1 = JapaneseCook()
client_1.add_food(2, 20)
client_1.add_drink(5, 4)
client_1.total() == "Sushi: 40, Tea: 20, Total: 60"

client_2 = RussianCook()
client_2.add_food(1, 40)
client_2.add_drink(5, 20)
client_2.total() == "Dumplings: 40, Compote: 100, Total: 140"

client_3 = ItalianCook()
client_3.add_food(2, 20)
client_3.add_drink(2, 10)
client_3.total() == "Pizza: 40, Juice: 20, Total: 60"

 

All data here will be correct and you don't need to implement the value checking.

(여기에있는 모든 데이터는 정확하며 값 확인을 구현할 필요가 없습니다.)

 

Input: Statements and expressions of the 3 chefs’ classes.

        (3 명의 요리사 클래스의 문장 및 표현.)

 

Output: The behaviour as described.

           (설명 된대로 동작)

 

How it is used: Work with classes and object-oriented programming is considered to be on a much higher skill level which you should reach in order to put Python to full use.

(클래스 사용 및 객체 지향 프로그래밍은 Python을 최대한 활용하기 위해 도달해야하는 훨씬 높은 기술 수준으로 간주됩니다.)

 

Precondition: All data is correct.

                  (모든 데이터가 정확합니다.)

 

A>

class AbstractCook:
    def __init__(self):
        self.food_total_price = 0
        self.drink_total_price = 0

    def add_food(self, food_amount, food_price):
        self.food_total_price += food_amount * food_price

    def add_drink(self, drink_amount, drink_price):
        self.drink_total_price += drink_amount * drink_price

    def total(self):
        f, d = self.food_total_price, self.drink_total_price
        return f'{self.food}: {f}, {self.drink}: {d}, Total: {f + d}'

class JapaneseCook(AbstractCook):
    food, drink = 'Sushi', 'Tea'

class RussianCook(AbstractCook):
    food, drink = 'Dumplings', 'Compote'

class ItalianCook(AbstractCook):
    food, drink = 'Pizza', 'Juice'

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing

    client_1 = JapaneseCook()
    client_1.add_food(2, 30)
    client_1.add_food(3, 15)
    client_1.add_drink(2, 10)

    client_2 = RussianCook()
    client_2.add_food(1, 40)
    client_2.add_food(2, 25)
    client_2.add_drink(5, 20)

    client_3 = ItalianCook()
    client_3.add_food(2, 20)
    client_3.add_food(2, 30)
    client_3.add_drink(2, 10)

    assert client_1.total() == "Sushi: 105, Tea: 20, Total: 125"
    assert client_2.total() == "Dumplings: 90, Compote: 100, Total: 190"
    assert client_3.total() == "Pizza: 100, Juice: 20, Total: 120"
    print("Coding complete? Let's try tests!")

 

O>

Coding complete? Let's try tests!

Process finished with exit code 0

 

S>

https://py.checkio.org

반응형

'Python_Matter > Solve' 카테고리의 다른 글