1.用循环画五角星
from turtle import * color(\'yellow\',\'yellow\') begin_fill() while True: forward(100) right(144) if abs(pos())<1: break end_fill()
2.用循环语句画同心圆
import turtle for i in range(2,10): turtle.up() turtle.goto(0,-20*i) turtle.down() turtle.circle(20*i)
3.用while循环画太阳花
from turtle import * color(\'green\',\'white\') begin_fill() while True: forward(200) left(170) if abs(pos())<1: break end_fill() done()
4.用函数定义画五个五角星
from turtle import * setup(600,400) bgcolor(\'red\') color(\'yellow\') def h_draw(r): begin_fill() for i in range(5): forward(r) right(144) end_fill() def h_goto(x,y,z): up() goto(x,y) setheading(z) down() h_goto(-260,120,0) h_draw(120) h_goto(-110,160,40) h_draw(40) h_goto(-65,125,10) h_draw(40) h_goto(-55,55,40) h_draw(40) h_goto(-110,15,20) h_draw(40)
5.用函数定义画钻石花瓣的太阳花
import turtle turtle.color(\'red\') turtle.fillcolor(\'yellow\') turtle.begin_fill() def h_draw(t): t.fd(80) t.right(45) t.fd(80) t.right(135) for i in range(36): h_draw(turtle) h_draw(turtle) turtle.left(10) turtle.end_fill() turtle.right(90) turtle.pensize(5) turtle.color(\'green\') turtle.forward(300)
6.学号
a=input(\'请输入你的学号:\') print(\'你的年级是{}级\'.format(a[2:4])) print(\'你的专业序号是{}\'.format(a[8:10])) print(\'你的班级学号是{}\'.format(a[10:]))
7.星期几
s=\'星期一星期二星期三星期四星期五星期六星期日\' a=int(input(\'输入数字(1-7):\')) print(s[0+3*(a-1):3+3*(a-1)])
8.身份证
ID=input(\'请输入十八位身份证号码: \') if len(ID)==18: print("你的身份证号码是 "+ID) else: print("错误的身份证号码") ID_add=ID[0:6] ID_birth=ID[6:14] ID_sex=ID[14:17] ID_check=ID[17] if int(ID_add)==440101: print("省市区:广东省广州市市辖区") elif int(ID_add)==440102: print("省市区:广东省广州市东山区") elif int(ID_add)==440103: print("省市区:广东省广州市荔湾区") elif int(ID_add)==440104: print("省市区:广东省广州市越秀区") elif int(ID_add)==440105: print("省市区:广东省广州市海珠区") elif int(ID_add)==440106: print("省市区:广东省广州市天河区") year=ID_birth[0:4] moon=ID_birth[4:6] day=ID_birth[6:8] print("生日: "+year+\'年\'+moon+\'月\'+day+\'日\') if int(ID_sex)%2==0: print(\'性别:女\') else: print(\'性别:男\')
9.网址
s=\'https://docs.python.org/3.6/library/index\' t=\'.html\' add=s+\'turtle\'+t print(add)
10.练习“+”、“*”、“in”、“len()”、“eval()”