我一直在尝试为我的学校项目建立一个卫生系统,但是不管Monster_health是否在循环之外,我的朋友和我似乎都无法解决这个问题,该值一直在重置。
代码:
monster_health = 100
while monster_health > 0:
playeraction = input('Placeholder beast wants to fight you!!\n1) Basic Attack')
print(monster_health)
if playeraction == 1:
monster_health = monster_health-7
continue
if monster_health <= 0:
print('You killed the monster!! Gain nothing, this is a test you barbarian')
break
输出:
Placeholder beast wants to fight you!!
1) Basic Attack
100 #should print 97 but fails to
替换
if playeraction == 1:
从您的代码中,您正在更新怪物的生命值,然后对其进行更新,因此第一次将其设为“ 100”(初始值)。