AttributeError:模块“random”没有属性“randint”

0 python random python-3.x

代码:

import turtle
import random
turtle.penup()
for i in range(20):
    x=random.randint(-200,200)
    y=random.randint(-200,200)
    turtle.setposition(x,y)
    turtle.dot()
turtle.done()
Run Code Online (Sandbox Code Playgroud)

错误:

F:\Python>random.py
Traceback (most recent call last):
  File "F:\Python\random.py", line 2, in <module>
    import random
  File "F:\Python\random.py", line 5, in <module>
    x=random.randint(-200,200)
AttributeError: module 'random' has no attribute 'randint'
Run Code Online (Sandbox Code Playgroud)

小智 6

重命名您的文件。

确保没有名为 random.py 的文件。