你好,所以我有一个来自较大代码的一小段代码,用于显示游戏中敌人的生命值,但由于某种原因,即使我认为它应该停止,循环仍在继续,我有什么吗失踪或做错了?import pygame, sysimport timeimport randomimport osimport sqlite3import os.pathdamage_done = 1random_monster_health = random.randint(7,10)alive = Trueprint (random_monster_health)while alive == True: mob_health = random_monster_health - damage_done print ("mob health is {}" .format(mob_health)) if mob_health != 0: percent_damage_done = mob_health / int(random_monster_health) how_much_health_bar = 1180 * (percent_damage_done) else: pass random_monster_health = mob_health print(random_monster_health) if mob_health != 0: print("the monster is still alive") pass else: alive == False print ("the monster is dead") passprint("the loop has ended")
1 回答
动漫人物
TA贡献1815条经验 获得超10个赞
else:
alive == False
print ("the monster is dead")
pass
这部分是错误的。你正在alive比较False
它应该是
else:
alive = False
print ("the monster is dead")
旁注:您不需要在每个 if 语句中使用 pass。
添加回答
举报
0/150
提交
取消