random.randint 错误 [英] random.randint error
本文介绍了random.randint 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些看起来像这样的代码:
I have some code that looks something like this:
import random
n = 0
while n <= 50:
n = n+1
a = random.randint(1, 16)
b = random.randint(1, 5)
print n, ". ", a, "-", b, "= "
出于某种原因,在运行它时,我收到以下错误:AttributeError: 'module' object has no attribute 'randint'
.但是,在 IDLE 中运行相同的 random.randint 查询时我没有问题.我该如何解决这个问题?
For some reason, when running it, I get the following error: AttributeError: 'module' object has no attribute 'randint'
. However, I have no problems when running the same random.randint queries in IDLE. How can I fix this?
推荐答案
您在某处有另一个名为random"的模块.您是否将脚本命名为random.py"?
You have another module called "random" somewhere. Did you name your script "random.py"?
这篇关于random.randint 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文