简体   繁体   中英

Type Error when trying to move Turtle in Python

I'm try to move to turtle to random places to draw a star but when I run the code I get :

Traceback (most recent call last): File "so_quick_run.py", line 36, in

main() File "so_quick_run.py", line 34, in main move() File "so_quick_run.py", line 28, in move alex.goto(rng(), rng()) File

"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/turtle.py", line 1689, in goto self._goto(Vec2D(*x)) TypeError: type object argument after * must be a sequence, not NoneType

I think I'm getting this problem from using an RNG from my turtle's goto command.

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

As @DYZ mentioned, you're not returning anything in rng() just return the random number that you generate:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM