+ 2
Problems with loops
Do you ever play with codecombat? I was playing on it and they are 2 days I'm on this exercise. Goals: Your hero must survive under 4 statements use a loop to defeat the ogres This is the code they gave me: # Use while True loop hero.moveUp() while True: enemy = hero.findNearestEnemy() hero.attack(enemy1) hero.attack(enemy1) hero.attack(enemy1) They said me to insert "while True:" on second line and I did it but I died all the time. I also bought a shield but it doesn't do nothing. Can you help me?
2 Respuestas
+ 1
I'm not familiar with the game either, but it looks like you are attacking 'enemy1' while the one you found is 'enemy' .
0
I never played it and I have no idea what they wanted there, but a few things came to mind.
1. You only move once. Your moveUp() method call is outside the loop. Was this the idea?
2. Nothing breaks your while True loop. Maybe you’re dying of exhaustion?
Good luck!