編寫程序輸入一個列表,列表中的元素為身份證(18位),根據身份證號獲得生日信息,說明身份證的7到10表示出生年,11到12表示出生月,13到14表示出生日。
輸入:
id_cards = ['310101199005052115', '320507199812280150']
輸出:
310101199005052115:1990/05/05 320507199812280150:1998/12/28
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author: Roc-xb
"""
def get_birthday(id_card):
year = id_card[6:10]
month = id_card[10:12]
day = id_card[12:14]
print("{}:{}/{}/{}".format(id_card, year, month, day))
if __name__ == '__main__':
id_cards = ['310101199005052115', '320507199812280150']
for id_card in id_cards:
get_birthday(id_card)