刚开始学习python的时候,我想给自己一个挑战,但是遇到了一个我无法改变我的数字的问题。如果我从它中减去一个数字,然后在不同的代码行上再次从它减去另一个数字,它就不会从原来的数字中更新。我需要的是这样的东西:a= 100 b-20a-b=80a-b =60 -希望这是有意义的:)
def viper_battle():
print("viper has the first attack,")
while player_health >= 1 or viper_health >= 1:
viper_atk = random.choice(viper_turn_list)
if viper_atk == 1:
print("viper has attacked you leaving you at", player_health - viper_dmg, "health")
elif viper_atk == 2:
print("viper is performing ship repairs only dealing half damage to you")
elif viper_atk == 3:
print("oh no viper used a special allowing them to deal the same damage as the health they have leaving us at", player_health - viper_special)
if player_health <= 0:
print("you lost!")
sys.exit()
attack_1 = input("what is your move: ")
if attack_1 == "a" or attack_1 == "A":
print("Direct hit!", viper_health - player_base_dmg, "health remains of our enemy")
elif attack_1 == "s" or attack_1 == "S":
print("The swarm was set upon Viper dealing massive damage", viper_health - player_special,"health remains of our enemy")
elif attack_1 == "r" or attack_1 == "R":
print("repairs were made tou our ship", player_health + player_repair)
elif attack_1 == "d" or attack_1 == "D":
print("we could not handle the heat, we retreated successfully")
sys.exit
if viper_health <= 0:
print("we won this battle!")
sys.exit()发布于 2022-10-15 15:15:47
a = 100, b = 20, a-b =80当您说an = 80时,这只是一个计算(我们称之为表达式)。它不会改变a或b或其他任何东西的值。你想把你的结果分配给你能用的东西。
a = 100
b = 20
a = a - b # 80
a = a - b # 60https://stackoverflow.com/questions/74080616
复制相似问题