Python上的Turtle命令

时间:2015-08-03 12:19:33

标签: python turtle-graphics spiral

有人可以帮我解决以下几行代码,并解释为什么似乎没有发生任何事情:

非常感谢,

from turtle import *
import time

def poly( n, N ):
    """ draws n sides of an N-sided regular polygon """
    if n == 0:
        return
    else:
        forward( 50 )   # 50 is hard-coded at the moment...
        left( 360.0/N )
        poly( n-1, N )
        poly( 7, 7)
        return


def chai(size):
    """ our chai function! """
    if (size<50): 
        return
    else:
        forward(size)
        left(90)
        forward(size/2.0)
        right(90)
        right(90)
        forward(size)
        left(90)
        left(90)
        forward(size/2.0)
        right(90)
        backward(size)
        return

2 个答案:

答案 0 :(得分:1)

您需要调用您的函数。因此,在底部输入chai(100)poly(4, 6)或您要调用的任何内容。或者,您可以在shell,另一个文件或任何您想要调用它们的位置导入这些函数并在那里运行它们。

答案 1 :(得分:0)

你声明了函数,但是你从未调用它们。 它看起来运行正常。

poly(2,3) enter image description here