- 用循环画五角星
import turtle turtle.fillcolor('red') turtle.begin_fill() while True: turtle.forward(200) turtle.left(144) if abs(turtle.pos())<1: break turtle.end_fill() done()
- 用循环画同心圆
import turtle for i in range(4): turtle.up() turtle.goto(0,-20*i) turtle.down() turtle.circle(20*i)
- 用while循环画太阳花
import turtle turtle.color('red','yellow') turtle.begin_fill() while True: turtle.forward(300) turtle.left(170) if abs(turtle.pos())<1: break turtle.end_fill() done()
- 用函数定义画五个五角星
import turtle turtle.pensize(2) turtle.setup(600,400,0,0) turtle.color("yellow") turtle.bgcolor('red') turtle.fillcolor("yellow") def goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() goto(-250,100) def draw(r): turtle.begin_fill() for i in range(6): turtle.forward(r) turtle.right(144) turtle.end_fill() draw(100) goto(-120,160) turtle.right(90) draw(20) goto(-100,140) turtle.right(90) draw(20) goto(-100,100) turtle.right(180) draw(20) goto(-120,40) turtle.right(90) draw(20) turtle.hideturtle()
- 用函数定义画钻石花瓣的太阳花
import turtle def draw(t): t.forward(80) t.right(45) t.forward(80) t.right(135) for i in range(36): draw(turtle) draw(turtle) turtle.right(10)
- 输入学号,识别年级、专业、序号。
number=input("请输入你的学号") print("你的学号为%s"%number) print("你的年级为:",number[0:4]) if int(number[8:10])==44: print("网络工程二班") else: print("输入有误") print("序号为:",number[10:12])
- 输入1-7的数字,输出对应的“星期几”。
i=int(input()) s="一二三四五六日" print("星期",s[i])
- 识别身份证号中的省市区、年龄、性别。
import time #省份对应字典 provinces = { 11:'北京市', 12:'天津市', 13:'河北省', 14:'山西省', 15:'内蒙古自治区', 21:'辽宁省', 22:'吉林省', 23:'黑龙江省', 31:'上海市', 32:'江苏省', 33:'浙江省', 34:'安徽省', 35:'福建省', 36:'江西省', 37:'山东省', 41:'河南省', 42:'湖北省', 43:'湖南省', 44:'广东省', 45:'广西壮族自治区', 46:'海南省', 50:'重庆市', 51:'四川省', 52:'贵州省', 53:'云南省', 54:'西藏自治区', 61:'陕西省', 62:'甘肃省', 63:'青海省', 64:'宁夏回族自治区', 65:'新疆维吾尔自治区', 71:'台湾省', 81:'香港特别行政区', 91:'澳门特别行政区' } def shibie(IDcard): province = IDcard[0:2] birthYear = IDcard[6:10] localYear = time.strftime('%Y') age = int(localYear) - int(birthYear) sex = IDcard[16:17] print("省份为:",provinces.get(int(province))) print("年龄为:{}".format(age)) if int(sex) % 2 == 0: print("性别:女") else: print("性别:男") IDcard = input("请输入身份证:") shibie(IDcard)
- 用字符串操作生成python文档各库的网址(起始网址在这里https://docs.python.org/3.6/library/index.html)
x="https://docs.python.org/3.6/library/index" y=".html" add=x+y print(add)
转载于:https://www.cnblogs.com/wlh353/p/7520287.html