# Wishing Well (python) (help)

**URL:** <https://discourse.codecombat.com/t/wishing-well-python-help/13914>\
**Category:** Uncategorized\
**Created:** [February 15, 2018, 11:55pm UTC](https://discourse.codecombat.com/t/wishing-well-python-help/13914 "2018-02-15T23:55:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)\
**Post date:** [February 15, 2018, 11:55pm UTC](https://discourse.codecombat.com/t/wishing-well-python-help/13914/1 "2018-02-15T23:55:36Z")

</div>

This is my code ```less = "Nimis"  
more = "Non satis"  
requiredGold = 104

# This function calculates the sum of coin values.

def sumCoinValues(coins):  
total = 0  
for coin in coins:  
total += coin.value  
return total

def collectCoins(coins):  
for coin in coins:  
hero.moveXY(coin.pos.x, coin.pos.y)

while True:  
items = hero.findItems()  
goldAmount = sumCoinValues(items)  
if len(items) != 0:  
# If there is not enough gold, then say “Non satis”.  
if goldAmount \< requiredGold:  
hero.say(“Nimis”)  
elif goldAmount \> requiredGold:  
hero.say(“non satis”)  
elif goldAmount == requiredGold:  
collectCoins(items)

```python

```

---

<div class="post-metadata">

**Author:** ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)\
**Post date:** [February 15, 2018, 11:55pm UTC](https://discourse.codecombat.com/t/wishing-well-python-help/13914/2 "2018-02-15T23:55:44Z")

</div>

```python
less = "Nimis"
more = "Non satis"
requiredGold = 104

# This function calculates the sum of coin values. 
def sumCoinValues(coins):
    total = 0
    for coin in coins:
        total += coin.value
    return total

def collectCoins(coins):
    for coin in coins:
        hero.moveXY(coin.pos.x, coin.pos.y)

while True:
    items = hero.findItems()
    goldAmount = sumCoinValues(items)
    if len(items) != 0:
        # If there is not enough gold, then say "Non satis".
        if goldAmount < requiredGold:
            hero.say("Nimis")
        elif goldAmount > requiredGold:
            hero.say("non satis")
        elif goldAmount == requiredGold:
            collectCoins(items)

```

---

<div class="post-metadata">

**Author:** ![Hellenar](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/hellenar/32/9100_2.png) [@Hellenar](https://discourse.codecombat.com/u/Hellenar)\
**Post date:** [February 16, 2018, 12:24am UTC](https://discourse.codecombat.com/t/wishing-well-python-help/13914/3 "2018-02-16T00:24:32Z")

</div>

Use variables instead of the strings themselves (it’s confusing, I know, I made the same mistake too).

---

<div class="post-metadata">

**Author:** ![Gamestack](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Gamestack](https://discourse.codecombat.com/u/Gamestack)\
**Post date:** [February 17, 2018, 3:04am UTC](https://discourse.codecombat.com/t/wishing-well-python-help/13914/4 "2018-02-17T03:04:17Z")

</div>

Thanks:sweat\_smile:😃
