1. 程式人生 > >條件、循環、函數定義 練習

條件、循環、函數定義 練習

ont color 同心圓 war true style forward strong bsp

1.畫五角星

from turtle import*
for i in range(5):
forward(150)
right(144)

2.畫同心圓

from turtle import*
for i in range(5):
circle(30*(i+1))
write(10-i)
up()
goto(0,-30*(i+1))
down()

3.畫太陽花

from turtle import*
color(‘yellow‘,‘red‘)
bgcolor(‘green‘)
while True:
forward(180)
left(165)
if(abs(pos()))<1:
break

4.畫五個角星

from turtle import*
setup(600,400,0,0)
color(‘yellow‘)
bgcolor(‘red‘)
fillcolor(‘yellow‘)

def wjqgoto(x,y):
up()
goto(x,y)
down()

wjqgoto(-250,75)

begin_fill()

for i in range(5):
forward(120)
right(144)
end_fill()

wjqgoto(-120,150)

begin_fill()
for i in range(5):
forward(60)
right(144)
end_fill()

wjqgoto(-80,100)

begin_fill()
for i in range(5):
forward(60)
right(144)
end_fill()

wjqgoto(-90,35)

begin_fill()
for i in range(5):
forward(60)
right(144)
end_fill()

wjqgoto(-120,-25)

begin_fill()
for i in range(5):
forward(60)
right(144)
end_fill()

條件、循環、函數定義 練習