Hello,
The task:
Defeat ogres
Collect 3 coins
Whey this code is not working?
while True:
enemy = hero.findNearestEnemy()
if enemy and enemy.type == “munchkin”:
hero.attack(enemy)
item = hero.findNearestItem()
if item and item.type==“coin”:
hero.attack(item)
First check your equipment to make sure all methods are doable.
Also, why are you trying to attack a coin? Just move to it.
In the future, be sure to format your code according to the FAQ using the </> button.
it’s not a problem with attacking or moving to item. I need to defeat 3 ogres and collect 3 coins. with this code hero defeats 1 ogr and collects 1 coin and then loop breaks, and this is the problem. tusk must be made under 8 statemants,
You cannot attack an item. The reason the loop breaks is because there is no function like that. Inside the for loop, you need to first check if “enemy” is valid, then attack them. Then, check if “item” is valid. If so,