如何解决即时消息试图使一个健康栏的while循环,但得到除法错误
您好,因此我的较大代码中有一小段代码,旨在显示游戏中敌人的健康状况,但由于某些原因,即使我认为应该停止,循环仍在继续,是否存在某些问题我想念还是做错了?
import pygame,sys
import time
import random
import os
import sqlite3
import os.path
damage_done = 1
random_monster_health = random.randint(7,10)
alive = True
print (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")
pass
print("the loop has ended")
解决方法
else:
alive == False
print ("the monster is dead")
pass
这部分是错误的。您正在将alive
与False
应该是
else:
alive = False
print ("the monster is dead")
旁注:您不需要在每个if语句中使用pass。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。