gpt4 book ai didi

python - 属性错误: 'int' object has no attribute 'choice'

转载 作者:行者123 更新时间:2023-11-30 23:31:10 25 4
gpt4 key购买 nike

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

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

最佳答案

random = random.choice(accuracy)

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

关于python - 属性错误: 'int' object has no attribute 'choice' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20126320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com