【发布时间】:2013-12-05 00:05:18
【问题描述】:
我打开了一个命令提示符,看看为什么这段代码不起作用,它说:
AttributeError: 'module' object has no attribute 'randint'
import random
print('I am thinking of a number between 1 and 50')
number = random.randint(1, 50)
guess = int(input('Can you guess what it is: '))
while guess != number:
if guess > number:
print('Lower...')
else:
print('higher...')
guess = int(input('Can you guess what it is: '))
print('Correct!')
input('\n\nEnter.')
【问题讨论】:
-
您似乎还有另一个名为 random 的模块。如果是这样,您必须将其重命名为不同的名称以避免命名空间问题
-
也许你已经将你的 python 文件命名为 random.py ?
-
请给我们完整真实的回溯,而不是平淡无奇的文字。
-
代码对我来说很好,也许你的文件名是 random.py ?或者你有另一个名为 random 的模块?
标签: python attributeerror