首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >难以保存号码

难以保存号码
EN

Stack Overflow用户
提问于 2022-10-15 15:08:24
回答 1查看 21关注 0票数 0

刚开始学习python的时候,我想给自己一个挑战,但是遇到了一个我无法改变我的数字的问题。如果我从它中减去一个数字,然后在不同的代码行上再次从它减去另一个数字,它就不会从原来的数字中更新。我需要的是这样的东西:a= 100 b-20a-b=80a-b =60 -希望这是有意义的:)

代码语言:javascript
复制
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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-15 15:15:47

a = 100, b = 20, a-b =80当您说an = 80时,这只是一个计算(我们称之为表达式)。它不会改变ab或其他任何东西的值。你想把你的结果分配给你能用的东西。

代码语言:javascript
复制
a = 100
b = 20
a = a - b # 80
a = a - b # 60
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74080616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档