代码
"""
功能:通过身份证判断年龄
作者:温胡可
时间:202.11.22
"""
import datetime
ID = input('请输入身份证号:')
while True:
if len(ID) == 18:
break
else:
ID = input('输入身份证无效,请重新输入身份证号:')
year = int(datetime.date.today().year)
month = int(datetime.date.today().month)
day = int(datetime.date.today().day)
age = year - int(ID[6:10])
if month - int(ID[10:12]) >= 0:
if day - int(ID[12:14]) >= 0:
print('年龄:{}'.format(age))
else:
age = age - 1
print('年龄:{}'.format(age))