+ 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
6 Antworten
+ 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!")
+ 3
The one that Rora posted works. I've tried it several times on the code.
+ 2
https://code.sololearn.com/cH9FIwZ6HsI4/?ref=app
I tried it. Everytime says draw. What's wrong?
+ 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")
+ 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
0
the game varied in winning when i just tried it out. i think its randomly maybe?