为什么主人公在python 3.7中虽然领先,但还是失败了?
这是我的密码:为什么主人公在python 3.7中虽然领先,但还是失败了?,python,python-3.x,Python,Python 3.x,这是我的密码: Krotos = [100, 25] Sephiroth = [100, 25] endGame = 0 def checkHealth(): global endGame if Krotos[0] == 0: print("Game Over") endGame = 1 if Sephiroth[0] == 0: print("You Win") endGame = 1 def krotosAttack(): Sephir
Krotos = [100, 25]
Sephiroth = [100, 25]
endGame = 0
def checkHealth():
global endGame
if Krotos[0] == 0:
print("Game Over")
endGame = 1
if Sephiroth[0] == 0:
print("You Win")
endGame = 1
def krotosAttack():
Sephiroth[0] -= Krotos[1]
def sephirothAttack():
Krotos[0] -= Sephiroth[1]
while endGame == 0:
krotosAttack()
checkHealth()
while endGame == 0:
sephirothAttack()
checkHealth()
让你知道我是python新手。我想做一个基于文本的游戏,但当我运行while循环时,它显示Krotos输了,即使他先去,他们的健康和伤害都一样。看看最后一个区块。
1) 它进入外环。
2) 克洛托斯发起了一次攻击。
3) 它进入内部循环。
4) 塞菲洛夫发起攻击
5) 因为游戏还没有结束,所以它会回到内部循环的开始 因此,除非克洛托斯在第一次进攻中获胜,否则塞菲洛夫将继续进攻直到比赛结束
若要修复,请将内部while更改为if。内部while循环将重复,sephiroth肯定会首先死亡。您可能希望在一个循环中完成这项工作,而您的IDE将有一个分步调试程序来跟踪这种情况problem@xxMrPHDxx. 塞菲洛斯会赢,因为他耗尽了对手的生命周期。这是一个很好的、明确的问题,有一个合理的尝试+1.很高兴看到初学者遵守网站规则,问得好。继续努力,你就不会长时间成为初学者了。@mad物理学家我的坏。。克洛托斯会像他说的那样先死,先走一步