# 条件、循环、函数定义 练习

1、用循环画五角星

import turtle
turtle.color("yellow")
turtle.fillcolor("yellow")
turtle.begin_fill()
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()

2、用循环画同心圆

from turtle import *

for i in range(5):
up()
goto(0,-20*(i+1))
down()
circle(20*(i+1))

3、用while循环画太阳花

from turtle import *
color("red","yellow")
begin_fill()
while True:
forward(200)
left(170)
if abs(pos())<1:
break
end_fill()
done()

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

import turtle
turtle.setup(600,400,0,0)
turtle.color("yellow")
turtle.bgcolor("red")
turtle.fillcolor("yellow")

def cyz_goto(x,y):
turtle.up()
turtle.goto(x,y)
turtle.down()

def cyz_draw5(r):
turtle.begin_fill()
for i in range(5):
turtle.forward(r)
turtle.right(144)
turtle.end_fill()

cyz_goto(-250,100)
cyz_draw5(100)

cyz_goto(-135,170)
cyz_draw5(40)

cyz_goto(-100,120)
cyz_draw5(40)

cyz_goto(-100,70)
cyz_draw5(40)

cyz_goto(-135,20)
cyz_draw5(40)

turtle.hideturtle()

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

import turtle
turtle.color("orange")
turtle.fillcolor("blue")
turtle.begin_fill()
def draw_leng():
for i in range(1,3):
turtle.forward(100)
turtle.right(45)
turtle.forward(100)
turtle.right(135)

for i in range(1,37):
draw_leng()
turtle.right(10)
turtle.end_fill()
turtle.right(90)
turtle.forward(300)

6、输入学号，识别年级、专业、序号。

r=input("请输入学号：")
print("年级:",r[:4])
print("专业：",r[8:10],"网络工程")
print("学号：",r[10:12])

7、输入1-7的数字，输出对应的“星期几”。

weekstr="星期一星期二星期三星期四星期五星期六星期日"
weekid=eval(input("请输入星期数字（1-7）:"))
pos=(weekid-1)*3
print(weekstr[pos:pos+3])

posted on 2017-09-13 21:16  46陈远钊  阅读(168)  评论(0编辑  收藏  举报