-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo8.py
51 lines (39 loc) · 913 Bytes
/
demo8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf8 -*-
import datetime
def birth_date(x):
'''
提取出生日期
参数x: 18位身份证号
'''
return x[6:14]
def sex(x):
'''
提取性别
'''
y = int(x[16])
# 偶数是女,奇数是男
if y % 2 == 0:
return '女'
else:
return '男'
def age(x):
'''
计算年龄
'''
#从身份证中取年份
z = int(x[6:10])
#获取今年的年份
d = datetime.datetime.today().year
return d - z
if __name__ == '__main__':
import sys
while True:
print('请输入身份证号:')
x = sys.stdin.readline()
if len(x[:-1]) == 18:
print('出生日期: %s' % birth_date(x))
print('性别: %s' % sex(x))
print('年龄: %s' % age(x))
break
else:
print('身份证位数不对')