我正在尝试用 Python(3.3.2 版)创建一个简单的问答游戏,但不知道如何使表达式起作用。下面看到的“health”和“oppHealth”变量不会随着程序运行而改变,或者至少字符串显示不会显示它们发生变化。源代码:
import time
#Variables
health = 30
oppHealth = 30
playStr = str(health)
oppStr = str(oppHealth)
def startBattle():
print()
print('You face off against your opponent.')
print()
print("Your health is " + playStr + ".")
print("Your opponent's health is " + oppStr + ".")
time.sleep(2)
print()
print('The opponent attacks with Fire!')
time.sleep(2)
print()
attack = input('How do you counter? Fire, Water, Electricity, or Ice?')
if attack == ('Fire'):
print("You're evenly matched! No damage is done!")
time.sleep(3)
startBattle()
elif attack == ('Water'):
print("Water beats fire! Your opponent takes 5 damage!")
oppHealth - 5
time.sleep(3)
startBattle()
elif attack == ('Electricity'):
print("You both damage each other!")
health - 5
oppHealth - 5
time.sleep(3)
startBattle()
elif attack == ('Ice'):
print("Fire beats ice! You take 5 damage.")
health - 5
time.sleep(3)
startBattle()
startBattle()
我只是想让适当的健康变量减少 5- 并让健康显示字符串反映每次战斗发生时的变化。如果有人可以帮助我,我将不胜感激。如果我排除了任何可能对您有帮助的信息,请告诉我。