#KochDrawV1.pyimport turtledef koch(size,n): if n == 0: turtle.fd(size) else: for angle in [0,60,-120,60]: turtle.left(angle) koch(size/3,n-1) def main(): turtle.setup(800,400) turtle.penup() turtle.goto(-300,-50) turtle.pendown() turtle.pensize(2) k
import turtle as t def kehe(size,n): #递归函数 if n==0: t.fd(size) #阶数为0时,为一直线 else: for i in [0,60,-120,60]: t.left(i) kehe(size/3,n-1) def main(): t.screensize(600,600,"black") #调整画布大小,设置背景色为黑色 #t.setup(600,600,0,0) t.penup() t.goto(-100,100) t.pe
lambda sum = lambda x,y : x + y print(sum(3,3),type(sum)) 默认参数 def prints(str,times = 2) : print(str*times) prints("Tree",3) 变长参数 def sums(*a): res = 0 for i in a: res += i return res print(sums(1,2,3,4,5)) return def swap(a,b): return b,a print