Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

A fine mint Python

and no i don’t know how to format my code

@Joshua_Leon if you highlight the code and use the formatted text option it should display the code as code.

ok i tried that and reposted it did it work?

yes it did, great! I am looking at the code.

oh, i moved the findNearestEnemy below def attackEnemy(): it fixed the problem

You only find a single enemy at the very start of your code execution.

Read it out loud:

  1. You define pickUpCoin.
  2. You find the nearest enemy.
  3. You define attackEnemy.
  4. You start a while-true loop.
  5. You call attack enemy
  6. You check if enemy exists.
  7. You attack enemy.
  8. You call pick up coin.
  9. You find nearest coin.
  10. You check if coin exists.
  11. You move to the coin.
  12. Repeat (while-true loop)

Look at step #2.

1 Like
# Peons are trying to steal your coins!
# Write a function to squash them before they can take your coins.
def pickUpCoin():
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)
# Write the attackEnemy function below.
# Find the nearest enemy and attack them if they exist!
def attackEnemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
while True:
    attackEnemy() # ∆ Uncomment this line after you write an attackEnemy function.
pickUpCoin()

is this right?
It won’t collect the coins?

Please format your code with 3x ( ` ) before and after your code block, so I can see your indentation.

1 Like

I dont know how to do that sorry I am new?

Be sure to read the part about “radiant, harmonious formatting”

wow great service you cant help me !!! wow!

I did it for you this time, but keep in mind in the future that improperly formatted Python code is hard to debug.

After formatting your code, I noticed that pickUpCoins isn’t indented. So it is never ran. Is this what you intended to do?

1 Like

can you give me the lost vikking answer I dont understand it for like two weeks

def pickUpCoin():
coin = hero.findNearestItem()
if coin:
hero.moveXY(coin.pos.x, coin.pos.y)

Write the attackEnemy function below.

Find the nearest enemy and attack them if they exist!

enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
while True:
hero.attack(enemy)
pickUpCoin()

Its not working can you help??

help someone please give me their code

help
with a fine mint

What do you mean “their code”?
We don’t post solutions here. If you have a problem with a level you can describe your problem and we’ll try to help you.

just give me the answer

It’s not the best way to ask for help. I wrote before We don’t post solutions here. Please, describe your problem with this level. Also, it’s better to be polite if you don’t want to be banned (instead imperative phrases).

1 Like
# Peons are trying to steal your coins!
# Write a function to squash them before they can take your coins.
def pickUpCoin():
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y)
# Write the attackEnemy function below.
# Find the nearest enemy and attack them if they exist!
def attackEnemy():
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
while True:
    attackEnemy() # ∆ Uncomment this line after you write an attackEnemy function.
    pickUpCoin()

i dont know whats wrong with the code but it wont work can someone help me?