如何修复Attributive Error bool对象在python中没有属性选择

时间:2019-01-05 04:40:14

标签: python boolean

我已经在python中导入了'random模块,但是当我尝试使用random.randint或choices时,会出现布尔错误

CriticalRNG = ["Crit","Normal"]
attack = input("What attack would you like to choose? \n")
if str(attack) == attacks[2]:
    randomValue = random.randint(1,3)
    if randomValue > 1:
        print("You have succesfully stunned your opponent!")
        enemyStunned =True
    else:
        print("The attack failled!")
if str(attack) == attacks[1]:
    # this attack has critical hit of 10 damage but is normally 3 damage
    # it is weighted 1/3 critical
    critical = random.choices(CriticalRNG, weights = [1,2])
    if critical == "Normal":
        EnemyHP = EnemyHP - 3
    elif critical == "Crit":
        print("That was a critical hit!")
        EnemyHP = EnemyHP - 10
if str(attack) == attacks[0]:
    EnemyHP = EnemyHP - 5
print("Enemy has ",EnemyHP," health remaining!")

我希望关键打击技工和令人震惊的技工能够胜任工作,但是会出现布尔错误

1 个答案:

答案 0 :(得分:0)

您可以使用以下示例:

import random

print random.randint(45, 500)

list_example=['a','b','c','3','4']
print random.choice(list_example)

我的输出

  

83 c

您的答案尚不清楚。如果您添加错误或添加代码,将会获得更多信息