在Python中尝试移动Turtle时键入错误

在Python中尝试移动Turtle时键入错误,python,turtle-graphics,Python,Turtle Graphics,我尝试移动到海龟到随机的地方来画星星,但当我运行代码时,我得到: 回溯(最近一次调用last):文件“so_quick_run.py”,第36行, 在 “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/turtle.py”, 第1689行,后藤 self._goto(Vec2D(*x))TypeError:在*之后的type对象参数必须是序列,而不是NoneType 我想我是因为使用海龟的

我尝试移动到海龟到随机的地方来画星星,但当我运行代码时,我得到:

回溯(最近一次调用last):文件“so_quick_run.py”,第36行, 在

“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/turtle.py”, 第1689行,后藤 self._goto(Vec2D(*x))TypeError:在*之后的type对象参数必须是序列,而不是NoneType

我想我是因为使用海龟的goto命令中的RNG而遇到这个问题的

#Import turtle
import turtle
wn = turtle.Screen()
alex = turtle.Turtle()

#Turtle Setting
alex.speed(10)
alex.color("yellow")
wn.bgcolor("black")
wn.screensize(600,600)

#Drawing star
def star(alex):
  for x in range(5):
      alex.pendown()
      alex.forward(50)
      alex.right(144)
      alex.penup()

#Randon Number Generator
import random
def rng():
  for i in range(1):
    random.randint(-250,250)

#Moving turtle
def move():
    alex.penup()
    alex.goto(rng(), rng())
    alex.pendown()

#Main funaton
def main():
    for i in range(10):
        move()
        star(alex)
main()

#Ending the loop
wn.mainloop()

正如@DYZ提到的,在
rng()
中没有返回任何内容,只返回生成的随机数:

#Randon Number Generator
import random
def rng():
    for i in range(1):
        return random.randint(-250,250)

请包含完整的错误消息。您发布的代码中甚至没有
*
。另外,函数
rng()
没有返回任何内容。我运行了OP的代码,发现他提到的错误在库中的某个地方。编辑问题以添加堆栈跟踪(如果有帮助)。(在这种情况下,调用函数有错误)以及为什么在
rng()
中有一个循环?@Tushar:错误很明显。他使用了
alex.goto(rng(),rng())
,但是
rng()
的结果是
None
(正如@DYZ提到的)。所以调用是
alex。goto(None,None)
None
不是这些参数的有效值。@RickyKim:为什么将循环留在那里?你认为这有什么用吗(除了浪费计算时间)?@Matthias我想OP可能想用这个循环做点什么?如果不是,则应移除回路。
#Randon Number Generator
import random
def rng():
    for i in range(1):
        return random.randint(-250,250)