2013-11-21 226 views
1

我写一个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,) 

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

回答

3
random = random.choice(accuracy) 

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

相关问题