Anyone can fix my py code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Anyone can fix my py code?

I made a game. We have 2 warriors. They attacks blocks or heals themselves. If you kill your opponent system says You killed your opponent you won If your opponent kills you system says Your opponent killed you Sometimes, they killing them in same time. If this happens system says You killed your opponent you won Your opponent killed you I tried to print draw if this happens but it didn't work. Can someone fix this code? https://code.sololearn.com/c2b2dilMTP0B/?ref=app

8th May 2018, 7:58 PM
Ayastar
Ayastar - avatar
6 Answers
+ 3
hey =) i tried it like this, hope it helps. greez while (0 < hp1) and (0 < hp2): battle() if hp1 and hp2 <= 0: print("it's a draw. everybody dies.") elif hp1 <= 0: print("\nYou died.") elif hp2 <= 0: print("\nYou killed your opponent.\nYou won!")
8th May 2018, 8:26 PM
loeckchen[INACTIVE]
+ 3
The one that Rora posted works. I've tried it several times on the code.
8th May 2018, 11:50 PM
Eris Ashwood
Eris Ashwood - avatar
+ 2
https://code.sololearn.com/cH9FIwZ6HsI4/?ref=app I tried it. Everytime says draw. What's wrong?
8th May 2018, 8:34 PM
Ayastar
Ayastar - avatar
+ 2
Use this instead. It worked when I tested it. Hope it helps while (0 < hp1) and (0 < hp2): battle() if hp1 <= 0: print("\nYou died.") if (hp2 <= 0) and (hp1 > 0): print("\nYou killed your opponent.\nYou won!") if (hp2 <= 0) and (hp1 <= 0): print("\nDraw")
8th May 2018, 11:18 PM
Rora
+ 1
so i found, maybe the problem is the 0 in the first ifs statement in this block. so, since one of the hps has to be zero u can also test the draw like this: if hp1 == hp2
8th May 2018, 9:04 PM
loeckchen[INACTIVE]
0
the game varied in winning when i just tried it out. i think its randomly maybe?
8th May 2018, 8:40 PM
loeckchen[INACTIVE]