# Summit's gate pls help me (python)

**URL:** <https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420>\
**Category:** Level Help\
**Created:** [January 7, 2021, 5:16pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420 "2021-01-07T17:16:06Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [February 14, 2021, 12:33pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/42 "2021-02-14T12:33:04Z")

</div>

no just get rid of these `()` on this like

> [@milton.jinich](#):
>
> get rid of those quotes you don’t need them
> 
> > [@stefan\_grecu](#):
> >
> > ` elif (paladin.health < 200):`

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 12:34pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/43 "2021-02-14T12:34:38Z")

</div>

ok done  
and what i wanna know is why does it say that the paladin cant heal

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [February 14, 2021, 12:38pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/44 "2021-02-14T12:38:15Z")

</div>

check if the paladin can cast that using

```python
if friend.canCast("heal" target):

```

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 12:40pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/45 "2021-02-14T12:40:32Z")

</div>

> [@milton.jinich](#):
>
> `if friend.canCast("heal" target):`

stil doesnt work  
ill make a screen shot ok

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 12:41pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/46 "2021-02-14T12:41:54Z")

</div>

![heal problem](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/4/b/4b5d39e8cdd651723ded315185d16516547869d4.png)  
this is what it says

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [February 14, 2021, 1:00pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/47 "2021-02-14T13:00:31Z")

</div>

define friend and put it in a for-loop

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 1:03pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/48 "2021-02-14T13:03:17Z")

</div>

you mean like this?

```python
def commandPaladin(paladin):
    for friend in friends:
        if paladin.canCast("heal"):
            target = lowestHealthPaladin()
    if target:
        hero.command(paladin, "cast", "heal", target)
    elif paladin.health < 200:
        hero.command(paladin, "shield")
    else:
        target = paladin.findNearestEnemy()
    if target:
        hero.command(paladin, "attack", target)

```

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [February 14, 2021, 1:09pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/49 "2021-02-14T13:09:08Z")

</div>

more like this

```python
def commandPaladin(paladin):
    friends = hero.findFriends()
    for friend in friends:
        if paladin.canCast("heal"):
            target = lowestHealthPaladin()
        if target:
             hero.command(paladin, "cast", "heal", target)
      
      else:
           enemy = paladin.findNearestEnemy()
           if target:
                  hero.command(paladin, "attack", enemy)

```

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 1:10pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/50 "2021-02-14T13:10:46Z")

</div>

> [@stefan\_grecu](#):
>
> ![heal problem](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/4/b/4b5d39e8cdd651723ded315185d16516547869d4.png)

still the same it may be a bug

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [February 14, 2021, 1:16pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/51 "2021-02-14T13:16:45Z")

</div>

do his and put all your code in the for-loop

```python
friends = hero.findFriends()
    for friend in friends:

```

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 1:21pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/52 "2021-02-14T13:21:11Z")

</div>

so i need to put all this in a for-loop?!

```python
def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    for friend in friends:
        if friend.type != "paladin":
            continue
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend

    return lowestFriend

def commandPaladin(paladin):
    friends = hero.findFriends()
    for friend in friends:
        if paladin.canCast("heal"):
            target = lowestHealthPaladin()
        if target:
            hero.command(paladin, "cast", "heal", target)
        else:
            enemy = paladin.findNearestEnemy()
            if target:
                hero.command(paladin, "attack", enemy)

while True:
    commandPaladin()
    paladins = []
    enemies = hero.findNearestEnemy()
    greenFlag = hero.findFlag("green")
    blackFlag = hero.findFlag("black")
    violetFlag = hero.findFlag("violet")
    if violetFlag:
        friends = hero.findFriends()
        if friends:
            for friend in friends:
                if friend:
                    hero.command(friend, "move", violetFlag.pos)
    if greenFlag:
        hero.pickUpFlag(greenFlag)
    if blackFlag:
        hero.pickUpFlag(blackFlag)
        hero.attackDamage
    if hero.canCast("invisibility", hero):
        hero.cast("invisibility", hero)
    friends = hero.findFriends()
    for enemy in hero.findEnemies():
        friends = hero.findFriends()
        for friend in friends:
            e = friend.findNearestEnemy()
            if e:
                hero.command(friend, "attack", e)
    fire = hero.findNearestEnemy()
    if fire:
        if enemy.type == "catapult":
            hero.backstab(enemy)
        while fire.health > 0:
            if hero.canCast("invisibility", hero):
                hero.cast("invisibility", hero)
            hero.attack(fire)
            hero.attack(enemy)
        if enemy.type == "skelleton":
            hero.attack(enemy)
    if hero.health < 3000:
        commandPaladin()

```

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 1:23pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/53 "2021-02-14T13:23:19Z")

</div>

and how to begin the for-loop `for hero in heroes`  
like this?

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 1:27pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/54 "2021-02-14T13:27:20Z")

</div>

im asking cause i never put a whole code in a for-loop

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [February 14, 2021, 1:29pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/55 "2021-02-14T13:29:17Z")

</div>

No don’t do that. What is the problem now

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 1:29pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/56 "2021-02-14T13:29:50Z")

</div>

i dont know how i put a whole code in a for-loop 😅

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [February 14, 2021, 1:31pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/57 "2021-02-14T13:31:00Z")

</div>

show me your new code

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 1:31pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/58 "2021-02-14T13:31:16Z")

</div>

```python
def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    for friend in friends:
        if friend.type != "paladin":
            continue
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend

    return lowestFriend

def commandPaladin(paladin):
    friends = hero.findFriends()
    for friend in friends:
        if paladin.canCast("heal"):
            target = lowestHealthPaladin()
        if target:
            hero.command(paladin, "cast", "heal", target)
        else:
            enemy = paladin.findNearestEnemy()
            if target:
                hero.command(paladin, "attack", enemy)

while True:
    commandPaladin()
    paladins = []
    enemies = hero.findNearestEnemy()
    greenFlag = hero.findFlag("green")
    blackFlag = hero.findFlag("black")
    violetFlag = hero.findFlag("violet")
    
    if violetFlag:
        friends = hero.findFriends()
        if friends:
            for friend in friends:
                if friend:
                    hero.command(friend, "move", violetFlag.pos)
    if greenFlag:
        hero.pickUpFlag(greenFlag)
    if blackFlag:
        hero.pickUpFlag(blackFlag)
        hero.attackDamage
    if hero.canCast("invisibility", hero):
        hero.cast("invisibility", hero)
    friends = hero.findFriends()
    for enemy in hero.findEnemies():
        friends = hero.findFriends()
        for friend in friends:
            e = friend.findNearestEnemy()
            if e:
                hero.command(friend, "attack", e)
    fire = hero.findNearestEnemy()
    if fire:
        if enemy.type == "catapult":
            hero.backstab(enemy)
        while fire.health > 0:
            if hero.canCast("invisibility", hero):
                hero.cast("invisibility", hero)
            hero.attack(fire)
            hero.attack(enemy)
        if enemy.type == "skelleton":
            hero.attack(enemy)
    if hero.health < 3000:
        commandPaladin()

```

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [February 14, 2021, 1:31pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/59 "2021-02-14T13:31:53Z")

</div>

What is the problem now

---

<div class="post-metadata">

**Author:** ![stefan\_grecu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/stefan_grecu/32/20456_2.png) [@stefan\_grecu](https://discourse.codecombat.com/u/stefan_grecu)\
**Post date:** [February 14, 2021, 1:33pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/60 "2021-02-14T13:33:24Z")

</div>

i asked how do i put my whole code in a for-loop

---

<div class="post-metadata">

**Author:** ![milton.jinich](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/milton.jinich/32/21419_2.png) [@milton.jinich](https://discourse.codecombat.com/u/milton.jinich)\
**Post date:** [February 14, 2021, 1:34pm UTC](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420/61 "2021-02-14T13:34:07Z")

</div>

don’t do that. What is the problem when you run your code, does your hero die, you run out of time, and etc.

[Previous page](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420.md?page=2)

[Next page](https://discourse.codecombat.com/t/summits-gate-pls-help-me-python/26420.md?page=4)
