32-刘振威

导航

条件、循环、函数定义、字符串操作练习

1、用循环画五角星

from turtle import *
while True:
    forward(200)
    right(144)
    if abs(pos()) < 1:
        break

 

2、用循环画同心圆

from turtle import *
for i in range(5):
    pu()
    goto(0,-(i+1)*10)
    pd()
    circle((i+1)*10)

 

3、用while循环画太阳花

from turtle import *
while True:
   forward(200)
   left(170)
   if abs(pos()) < 1:
       break  
done()

 

4、用函数定义画五个五角星

from turtle import *
def a(x,y):
    pu()
    goto(x,y)
    pd()
    
def b():
    for i in range(5):
        forward(100)
        right(144)

for i in range(5):
    a(-(i*100),0)
    b()

 

5、用函数定义画钻石花瓣的太阳花

from turtle import *
def draw_lx():
    for i in range(1,3):
        forward(100)
        right(45)
        forward(100)
        right(135)

def draw_zuanshi():
    speed(10) 
    for i in range(36):
        draw_lx()
        right(10)
draw_zuanshi()

 

posted on 2017-09-13 20:22  32-刘振威  阅读(210)  评论(0编辑  收藏  举报