我正在写一个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,)
它会执行一次随机模块,然后生成错误 任何帮助表示赞赏。
答案 0 :(得分:3)
random = random.choice(accuracy)
您在第一次迭代中获得一个int值并将其存储在random
中,这是模块的名称。现在,random
变量隐藏了random
模块。最好的解决方法是使用其他变量名而不是random
。