标签:student 年龄 com nbsp draw sha 字符串操作 条件 .sh
用循环画五角星
import turtle turtle.fillcolor("red") turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.right(144) turtle.end_fill()
用循环画同心圆
import turtle for i in range(3): turtle.up() turtle.goto(0,-50*(i+1)) turtle.down() turtle.circle(50*(i+1))
用while循环画太阳花
import turtle turtle.color(‘red‘,‘yellow‘) turtle.begin_fill() while True: turtle.forward(200) turtle.left(170) if abs(turtle.pos()) < 1: break turtle.end_fill()
用函数定义画五个五角星
import turtle turtle.setup(600,400,0,0) turtle.color("yellow") turtle.bgcolor(‘red‘) turtle.fillcolor("yellow") def Mygoto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def Mydraw(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() Mygoto(-273,110) Mydraw(100) Mygoto(-121,162) turtle.left(45) Mydraw(50) Mygoto(-79,110) Mydraw(50) Mygoto(-79,51) turtle.right(45) Mydraw(50) Mygoto(-121,22) turtle.right(45) Mydraw(50)
用函数定义画钻石花瓣的太阳花
import turtle def Yyxdraw_diamond(brad): brad.forward(120) brad.right(45) brad.forward(120) brad.right(135) def Yyxdraw_art(): window=turtle.Screen() window.bgcolor("red") brad=turtle.Turtle() brad.shape("turtle") brad.color("yellow") for i in range(36): Yyxdraw_diamond(brad) Yyxdraw_diamond(brad) brad.left(10) window.exitonclick() Yyxdraw_art()
字符串操作:输入学号,识别年级、专业、序号。
majors = { 11:‘网络工程‘, 12:‘软件工程‘, 13:‘数字媒体‘, } def recognition(studentID): if len(studentID)<12: print("请输入正确的学号!") elif studentID.isdigit() != True: print("请输入正确的学号!") else: grade = studentID[0:4] major = studentID[6:8] num = studentID[10:12] print("年级:{}级".format(grade)) print("专业为:",majors.get(int(major))) print("序号:{}".format(num)) studentID = input("请输入学号:") recognition(studentID)
输入1-7的数字,输出对应的“星期几”。
s="星期一星期二星期三星期四星期五星期六星期天" i=int(input("请输入(1-7):")) if(0<i<8): print(s[-3+3*i:0+3*i]) else: print("输入有误!")
识别身份证号中的省市区、年龄、性别。
ID=input(‘请输入十八位身份证号码: ‘) if len(ID)!=18: print("错误的身份证号码!!") ID_add=ID[0:6] ID_birth=ID[6:10] ID_sex=ID[14: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("省市区:广东省广州市海珠区") birth=2017-int(ID_birth[0:4]) print("年龄:{}".format(birth)) if int(ID_sex)%2==0: print(‘性别:女‘) else: print(‘性别:男‘)
用字符串操作生成python文档各库的网址(起始网址在这里https://docs.python.org/3.6/library/index.html)
yyx1 = "https://docs.python.org/3.6/library/" yyx2 = ".html" yyx3 = input("请输入库名:") print("网址为:%s%s%s"%(yyx1,yyx3,yyx2))
练习字符串的+,*,in,len(),eval()
print("No!"*3) s="this is " t="younger!" print(s+t) p="hello world!!!" for i in range(len(s)): print(i,s[i])
标签:student 年龄 com nbsp draw sha 字符串操作 条件 .sh
原文地址:http://www.cnblogs.com/zj2017/p/7523893.html