AttributeError:module' random'没有属性' randint'

时间:2018-04-01 14:58:07

标签: python python-3.x random

代码:

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()

错误:

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'

1 个答案:

答案 0 :(得分:0)

更改文件名 请注意,没有文件名为random.py