标签:orm 身份证 代码 import 标准库 war 字符串操作 span col
from turtle import * for i in range(5): up() goto(0,-20*i) down() circle(20*i)
from turtle import * for i in range(5): forward(200) right(144)
from turtle import * color(‘red‘,‘yellow‘) speed(‘fastest‘) begin_fill() while True: forward(200) left(170) if abs(pos())<1: break end_fill() done()
用函数定义画钻石花瓣的太阳花
import turtle def draw_diamond(brad): brad.forward(100) brad.right(45) brad.forward(100) brad.right(135) def draw_art(): window=turtle.Screen() window.bgcolor("purple") brad=turtle.Turtle() brad.shape("turtle") brad.color("orange") brad.speed("fastest") for i in range(0,36): draw_diamond(brad) draw_diamond(brad) brad.left(10) brad.right(90) brad.forward(155) brad.color(‘green‘) brad.forward(145) window.exitonclick() draw_art()
3.字符串操作
输入学号,识别年级、专业、序号。
def shibie(studentID): if len(studentID)<12: print("请输入正确的学号!") elif studentID.isdigit() != True: print("请输入正确的学号!") else: grade = studentID[0:4] profession = studentID[4:8] order = studentID[10:12] print("年级:{}级".format(grade)) if profession == "0611": print("专业:网络工程") print("序号:{}".format(order)) studentID = input("请输入学号:") shibie(studentID)
输入1-7的数字,输出对应的“星期几”。
#coding=gbk x = input("Please enter an integer:") x = int(x) if x ==1 : print (‘星期一‘) elif x == 2: print (‘星期二‘) elif x == 3: print (‘星期三‘) elif x == 4: print (‘星期四‘) elif x == 5: print (‘星期五‘) elif x == 6: print (‘星期六‘) elif x == 7: print (‘星期七‘) else: print (‘the number is wrong!‘)
识别身份证号中的省市区、年龄、性别。
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)
标签:orm 身份证 代码 import 标准库 war 字符串操作 span col
原文地址:http://www.cnblogs.com/huanglinxin/p/7517518.html