본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 73

반응형

Q>

One day, on a typical spring afternoon, Sir Ronald has been looking around his land, riding a horse.

(어느 날, 전형적인 봄 오후, Ronald 경은 말을 타고 그의 땅을 둘러 보았습니다.)

Nothing foretold troubles, when suddenly Sir Ronald heard a scream for help, coming from somewhere nearby:

(갑자기 Ronald 경이 근처 어딘가에서 오는 도움 소리를 듣자 갑자기 문제가 발생하지 않았습니다.)
- "Help! Help!" - shouted a piercing young girl's voice.

(- "도와 줘요!" - 피어싱 어린 소녀의 목소리를 외쳤다.)
As a true knight, Sir Ronald couldn’t stay away and went to the lady’s rescue.

(진정한 기사 인 로널드 경은 머무를 수 없었고 레이디의 구출 작전에갔습니다.)

Rushing in the direction from which the cry came, he saw a carriage.

(외침이 오는 방향으로 돌진하면서, 그는 마차를 보았다.)

The girl peered out the window hoping to see someone who could help her.

(소녀는 그녀를 도울 수있는 누군가를 만나기를 희망하면서 창문을 들여다 보았다.)
- "Stop!"- ordered Sir Ronald to the coachman. - "By what right are you on my land?"

(- "그만!"- 코치 맨에게 로널드 경에게 명령했다. "너는 내게 어떤 권리가 있니?")
The coachman didn’t get a chance to open his mouth, as his master came out of the carriage.

(그의 주인이 마차에서 나왔을 때, 코치 맨은 입을 벌 수있는 기회를 얻지 못했습니다.)
- "My respects, noble sir.

(- "내 존경, 고귀한 선생님.)

I had no idea that this land is yours.

(나는 이 땅이 너의 것임을 전혀 몰랐다.)

My bride and I were just going to my estate, not wanting to give anyone any trouble. "

(내 신부와 나는 단지 내 재산에 갈 것이고 누군가에게 아무런 문제가 없기를 바랄 뿐이다. ")
- "A flat-out lie! I'm not his bride!" - the girl exclaimed from the window.

(- "평평한 거짓말! 나는 그의 신부가 아니야!" 여자애가 창문에서 외쳤다.)
- "Explain yourself, Sir. What does that mean?",- said Sir Ronald. 

(- "너 자신을 설명해주십시오, 그게 무슨 뜻입니까?"- 로널드 경이 말했다.)
- "Of course.

(- "당연하지.)

The king of a neighboring country has promised his daughter and half his kingdom to the one who’ll save her from the outlaws who took her.

(이웃 국가의 왕은 딸을 데려 간 무법자를 구할 자에게 딸의 왕국과 왕국의 절반을 약속했다.)

I’ve defeated those bastards and now I’m taking the princess to her father. "

(나는 그 놈들을 물리 치고 공주를 아버지에게 데려 가고 있습니다. ")
- "It's not true!

(- "그것은 사실이 아닙니다!)

They were in on it together They’ve kidnapped me on his order!

(그들은 그것에 함께 있었다 그들은 그들의 명령에 따라 나를 납치했다!)

I saw how he paid them a bag of gold!"

(나는 그들이 금낭을 어떻게 지불했는지 보았다. ")

- The princess didn’t stop taking for a second, trying to quickly describe the situation to the miraculously appeared savior. 

(- 공주는 기적적으로 등장한 구원자에게 상황을 신속하게 설명하기 위해 잠시 쉬는 것을 멈추지 않았습니다.)
- "Such behavior is unworthy of a knight! Prepare to die!",

(- "그런 행동은 기사의 가치가 없다! 죽을 준비를하라!",)

- exclaimed Sir Ronald, drawing his sword.

(- 로널드 경이 그의 칼을 그리며 외쳤다.)

- "Ha-ha-ha, simple-hearted nobleman!

(- "하하하, 심심한 귀족!)

We’ll see about that..."

(우리는 그것에 대해 알게 될 것입니다 ... ")

 

I'm sure that many of you have some experience with computer games.

(많은 사람들이 컴퓨터 게임에 대한 경험이있는 것으로 확신합니다.)

But have you ever wanted to change the game so that the characters or a game world would be more consistent with your idea of the perfect game?

(그러나 캐릭터 나 게임 세계가 완벽한 게임에 대한 아이디어와 더 일치하도록 게임을 변경하고 싶습니까?)

Probably, yes.

(아마, 네. )
In this mission (and in several subsequent ones, related to it) you’ll have a chance "to sit in the developer's chair" and create the logic of a simple game about battles.

(이 임무 및 여러 후속 작업)에서는 개발자의 의자에 앉아 전투에 대한 간단한 게임의 논리를 만들 수있는 기회가 주어집니다.)
Let's start with the simple task - one-on-one duel.

(간단한 일부터 시작합시다 - 1 대 1 결투.)

You need to create the class Warrior, the instances of which will have 2 parameters - health (equal to 50 points) and attack (equal to 5 points), and 1 property - is_alive, which can be True (if warrior's health is > 0) or False (in the other case).

(Warrior 클래스를 생성해야합니다.이 인스턴스에는 건강 (50 점)과 공격 (5 점), 1 속성 - is_alive의 두 가지 매개 변수가 있습니다.이 값은 True 일 수 있습니다 (전사의 건강 상태가 0보다 큰 경우). ) 또는 거짓 (다른 경우).)

In addition you have to create the second unit type - Knight, which should be the subclass of the Warrior but have the increased attack - 7.

(또한 Warrior의 서브 클래스가되어야하지만 증가 된 공격력을 가진 Knight라는 두 번째 유닛 유형을 생성해야합니다.)

Also you have to create a function fight(), which will initiate the duel between 2 warriors and define the strongest of them.

(또한 당신은 2 명의 전사 사이에서 결투를 시작하고 그들 중 가장 강한 것을 정의 할 function fight () 함수를 만들어야합니다.)

The duel occurs according to the following principle:

( 결투는 다음 원칙에 따라 발생합니다.)
every turn one of the warriors will hit another one and the last will lose his health in the same value as the attack of the first warrior.

(전사의 매 턴마다 다른 전사를 치고 마지막 전사는 첫 번째 전사의 공격과 동일한 가치로 자신의 건강을 잃어 버리게됩니다.)

After that, the second warrior will do the same to the first one.

(그 후, 두 번째 전사는 첫 번째 전사와 동일하게 행동 할 것입니다.)
If in the end of the turn the first warrior has > 0 health and the other one doesn’t, the function should return True, in the other case it should return False.

(턴의 마지막에 첫 번째 전사가 0보다 크고 다른 하나가 그렇지 않으면 함수는 True를 반환해야하고, 다른 경우에는 False를 반환해야합니다.)

 

Example:

chuck = Warrior()
bruce = Warrior()
carl = Knight()
dave = Warrior()

fight(chuck, bruce) == True
fight(dave, carl) == False
chuck.is_alive == True
bruce.is_alive == False
carl.is_alive == True
dave.is_alive == False

 

Input: The warriors.

         (전사.)

 

Output: The result of the duel (True or False).

           (결투 결과 (참 또는 거짓).)

 

How it is used: For computer games development.

                     (컴퓨터 게임 개발 용.)

 

Precondition: 2 types of units

                  (2 가지 유형의 단위)

 

A>

class Warrior:
    health : int = 50
    is_alive : bool = True
    attack : int = 5

class Knight(Warrior):
    attack = 7

def fight(unit_1, unit_2):
    while unit_1.is_alive and unit_2.is_alive:
        unit_2.health -= unit_1.attack
        unit_1.health -= unit_2.attack
        if unit_2.health <= 0:
            unit_2.is_alive = False
            return True
        elif unit_1.health <= 0:
            unit_1.is_alive = False
            return False

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

    chuck = Warrior()
    bruce = Warrior()
    carl = Knight()
    dave = Warrior()
    mark = Warrior()

    assert fight(chuck, bruce) == True
    assert fight(dave, carl) == False
    assert chuck.is_alive == True
    assert bruce.is_alive == False
    assert carl.is_alive == True
    assert dave.is_alive == False
    assert fight(carl, mark) == False
    assert carl.is_alive == False

    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' 카테고리의 다른 글

Python Learn the basics Quiz 75  (0) 2019.06.20
Python Learn the basics Quiz 74  (0) 2019.06.20
Python Learn the basics Quiz 72  (0) 2019.06.19
Python Learn the basics Quiz 71  (0) 2019.06.17
Python Learn the basics Quiz 70  (0) 2019.06.15