Problems with loops | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

28th May 2018, 10:22 PM
Parsix3
Parsix3 - avatar
2 Answers
+ 1
I'm not familiar with the game either, but it looks like you are attacking 'enemy1' while the one you found is 'enemy' .
7th Jun 2018, 1:08 AM
1_coder
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!
29th May 2018, 2:15 AM
Pedro Demingos
Pedro Demingos - avatar