python 3.4 spirograph错误

时间:2014-09-10 16:13:58

标签: python python-3.x

from turtle import*                                                                      
from math import*

def Xcord(R,r,p,t):  

    x= (R-r) * cos(t) - (r+p) * cos((R-r)//r*t)

def Ycord (R,r,p,t):

    y= (R-r) * sin(t) - (r+p) * sin((R-r)//r*t)

def t_iter(R,r,p):

      t=0
      down()
      goto(Xcord(R,r,p,t),Ycord(R,r,p,t))
      while (t < 2 * pi):
          t = t+.01
          Xcord(R,r,p,t)
          Ycord(R,r,p,t)
          up()
      return

def main():

      R=100
      r=4
      p=int(input("Please enter a number between 10 and 100: "))
      if p < 10 or p > 100:
            input(" Incorrect value of p!")
      t_iter(R,r,p)
      input("Hit enter to close porgram")
      bye()

main()

我收到此错误:

Traceback (most recent call last):

  File "C:/Users/Coscio/Desktop/spirals.py", line 31, in <module>
    main()

  File "C:/Users/Coscio/Desktop/spirals.py", line 27, in main
    t_iter(R,r,p)

  File "C:/Users/Coscio/Desktop/spirals.py", line 13, in t_iter
    goto(Xcord(R,r,p,t),Ycord(R,r,p,t))

  File "<string>", line 1, in goto

  File "D:\Python\lib\turtle.py", line 1774, in goto
    self._goto(Vec2D(*x))

TypeError: type object argument after * must be a sequence, not NoneType

1 个答案:

答案 0 :(得分:0)

from turtle import*

from math import*

def Xcord(R,r,p,t):

        return (R-r) * cos(t) - (r+p) * cos((R-r)//r*t)

def Ycord (R,r,p,t):
    return (R-r) * sin(t) - (r+p) * sin((R-r)//r*t)

def t_iter(R,r,p):
    t=0
    up()
    Xcord(R,r,p,t)
    Ycord(R,r,p,t)
    while (t < 2 * pi):
        t = t+.01
        goto(Xcord(R,r,p,t),Ycord(R,r,p,t))
        down()
    return float(Xcord(R,r,p,t))
    return float(Ycord(R,r,p,t))

def validate():
    while True:
        p=int(input("Please enter a number between 10 and 100: "))
        if p >= 10 or p <= 100:
            break
    return p


def main():
    speed(0)
    R=100
    r=4
    p = validate()
    t_iter(R,r,p)
    Xcord(R,r,p,t_iter(R,r,p))
    Ycord(R,r,p,t_iter(R,r,p))
    input("Hit enter to close porgram")
    bye()

main()