Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

The enemy in my game is not dying

+3 votes
asked Nov 2, 2022 by Yoong Tsun Chuen (550 points)

Neither is the player.

Nor can the player spare the enemy

Please help me fix it if possible.


2 Answers

0 votes
answered Nov 2, 2022 by Eidnoxon (5,270 points)
Hi! I fixed your code!:


Don't ask me what i did, i just wrote the same code, but shorter, and it seems like it works.
commented Nov 2, 2022 by Eidnoxon (5,270 points)
Oh wait. No, it doesn't works. I think you should put the ending to a function, so it will be more readable.
commented Nov 2, 2022 by Eidnoxon (5,270 points)
Ok, now i REALLY found the problem in your code. This time really. Put the "if crabhp <= 0:" etc. line of code inside the first while loop, and then at the last if statement use the break method. If it doesn't works, then idk.
0 votes
answered Nov 3, 2022 by Peter Minarik (88,520 points)

Your main loop has the wrong conditions. Try this instead:

while mercy == 0 and hp > 0 and crabhp > 0:

meaning, that you only do the loop as long as

  • no mercy is shown AND
  • the player is still alive AND
  • the crab is still alive

In other words the game ends if

  • mercy is shown OR
  • the player is dead OR
  • the crab is dead

I hope this helps.

Good luck!

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.