首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >继续循环回到初始值python

继续循环回到初始值python
EN

Stack Overflow用户
提问于 2018-06-21 08:56:42
回答 4查看 101关注 0票数 0

我尝试学习python只有3个星期,所以我不完全确定我在做什么。我正在尝试做一个简短、简单和愚蠢的游戏,我使用randint在玩家和计算机之间的战斗中给出一个随机值。健康值一直循环回到原始值,我似乎找不出原因……已经找了好几天了。我设置了一个中断来停止战斗,但它的‘健康’也没有达到零。谢谢你的帮助。

代码语言:javascript
复制
from random import randint

n = input()
print ('Welcome, ', n, ' Choose your weapon: Sword, Axe, or Mace.')
b = input()

if b == {'Sword'}:
    print ('Good Choice ', (n), ' the Sword will keep you safe.')
elif b == {'Axe'}:
    print ('Good Choice ', (n), ' the Axe will do some damage.')
elif b == {'Mace'}:
    print ('Probably a bad choice ', (n), ' the mace is heavy and slow but may protect you.')

print ('The Knight Approaches! ', (n), ', Get your', (b),' and get ready!')


player = 50 
knight = 50

battle = True

while player >= 0  or knight >= 0:

    if b == 'Sword':
        k2 = (knight - randint(3,4)) 
        p2 = (player - randint(2,6))
        print ('You have struck the knight!  His health is now', k2)
        print ('He has hit you as well!  Your health is now', p2)

    elif b == 'Axe':
        print ('You have struck the knight!  His health is now', knight - randint(2,6))
        print ('He has hit you as well!  Your health is now', player - randint(3,4))

    elif b == 'Mace':
        print ('You have struck the knight!  His health is now', knight - randint(0,7))
        print ('He has hit you as well!  Your health is now', player - randint(2,6))

    if player <= 0: 
        print ('You have died...')
    elif knight <= 0:
        print ('You have won!')

    break

print ('Good Game')
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50958938

复制
相关文章

相似问题

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