import turtle
c = turtle.Turtle()
c.circle(100)
import turtle
c = turtle.Turtle()
c.circle(100)
c.left(10)
c.circle(100)
c.left(10)
上圖迴圈的寫法
import turtle
c = turtle.Turtle()
i = 0
while i < 2:
c.circle(100)
c.left(10)
i += 1
因為圓有360度,每次都向左10度,只要連續轉36次,就會變得很好看
import turtle
c = turtle.Turtle()
i = 0
while i < 36:
c.circle(100)
c.left(10)
import turtle
c=turtle.Turtle()
for i in range(36):
c.circle(100)
c.left(10)
i += 1
用遞迴的想法來設計
import turtle
c=turtle.Turtle()
def circle_recursion(i):
if(i>0):
c.circle(100)
c.left(10)
circle_recursion(i-1)
return
circle_recursion(36)
接下來來看看IF
import turtle
c = turtle.Turtle()
i = 0
while i < 36:
i += 1
if i% 2 == 0:
c.circle(100)
c.left(10)
不妨把輸入程式觀察其形為
沒有留言:
張貼留言