属性错误:'int'对象没有属性'choice'

时间:2013-11-21 16:19:15

标签: python python-3.x attributeerror

我正在写一个python程序,我收到了这个错误:

Traceback (most recent call last):
File "C:\Users\Joe\SkyDrive\Documents\Python Project\Python\Forest path.py", line 28, in   <module>
random = random.choice(accuracy)
AttributeError: 'int' object has no attribute 'choice'

以下是它所指的一些代码:

while health_1 > 0 and health > 0 and stamina > 0:
    random = random.choice(accuracy)
    if random != "0":
        print("\n\n", random)
        print("\nYou manage to hit the creature for", dmg, "damage!")
        health_1 -= dmg
        stamina -= stam_loss
        print("The creature now has", health_1, "health")
        print("\nThe creature hits you for 1 damage!")
        health -= 1
        print("Health:", health, "Stamina:", stamina,) 

它会执行一次随机模块,然后生成错误 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:3)

random = random.choice(accuracy)

您在第一次迭代中获得一个int值并将其存储在random中,这是模块的名称。现在,random变量隐藏了random模块。最好的解决方法是使用其他变量名而不是random

相关问题