标签:曲线 code exce 雪花 eval rtl one koch span
#我的代码
1 import turtle 2 def koch(size, n): 3 if n == 0: 4 turtle.fd(size) 5 else: 6 for angle in [0, 60, -120, 60]: 7 turtle.left(angle) 8 koch(size/3, n-1) 9 10 def main(level): 11 turtle.setup(600,600) 12 turtle.penup() 13 turtle.goto(-200, 100) 14 turtle.pendown() 15 turtle.pensize(2) 16 koch(400, level) 17 turtle.hideturtle() 18 turtle.done() 19 20 try: 21 level = eval(input("请输入科赫曲线的阶: ")) 22 main(level) 23 except: 24 print("输入错误")
答案:
1 import turtle 2 def koch(size, n): 3 if n == 0: 4 turtle.fd(size) 5 else: 6 for angle in [0, 60, -120, 60]: 7 turtle.left(angle) 8 koch(size/3, n-1) 9 10 def main(level): 11 turtle.setup(600,600) 12 turtle.penup() 13 turtle.goto(-200, 100) 14 turtle.pendown() 15 turtle.pensize(2) 16 koch(400,level) 17 turtle.right(120) 18 koch(400,level) 19 turtle.right(120) 20 koch(400,level) 21 turtle.hideturtle() 22 23 try: 24 level = eval(input("请输入科赫曲线的阶: ")) 25 main(level) 26 except: 27 print("输入错误")
标签:曲线 code exce 雪花 eval rtl one koch span
原文地址:https://www.cnblogs.com/chezxj/p/12534906.html