Python 当我的条件为false时,当它变为true时,为什么循环不停止
这是我的密码 在Python3.4中,它只是一直运行循环,直到玩家死亡时系统退出。这是我一直在玩的rpg游戏的一部分 非完整代码请注意,如果您想查看完整代码,请仅询问显示的作战功能Python 当我的条件为false时,当它变为true时,为什么循环不停止,python,function,python-3.x,while-loop,statements,Python,Function,Python 3.x,While Loop,Statements,这是我的密码 在Python3.4中,它只是一直运行循环,直到玩家死亡时系统退出。这是我一直在玩的rpg游戏的一部分 非完整代码请注意,如果您想查看完整代码,请仅询问显示的作战功能 def combat(h, a, d, x): global attack global health global defence global xp death = False while death == False: eab = random.r
def combat(h, a, d, x):
global attack
global health
global defence
global xp
death = False
while death == False:
eab = random.randint(1, 10)
yab = random.randint(1, 10)
cattack = 0
cdefence = 0
cattack = attack
cdefence = defence
cattack = cattack + yab
a = a + eab
d = d - cattack
print("you strike for " + str(cattack) + " damage")
cattack = cattack - d
if cattack > 0:
h = h - cattack
if d > 0:
print("the enemy has " + str(d) + "defence left")
if h > 0:
print("the enemy has " + str(h) + "Health left")
else :
print("the enemy dies")
death == True
xp = xp + x
print("they strike back for " + str(a))
cdefence = cdefence - a
a = a - cdefence
if a > 0:
health = health - a
if cdefence > 0:
print("you have " + str(cdefence) + " defence left!")
if health > 0:
print("you have " + str(health) + " health left")
else :
sys.exit("YOU DIED A HORRIBLE DEATH")
你的问题是这行:死亡==真 这将变量“death”与True函数进行比较,后者永远不会起作用。你需要做的是用death=True替换它 这将修复您的代码。death==True。你不是在给死亡赋值,你只是在比较它们。