程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python reads birthday information in ID card

編輯:Python

Write a program to enter a list , The elements in the list are ID cards (18 position ), Get birthday information according to your ID number , State the ID card 7 To 10 Indicates the year of birth ,11 To 12 Indicates the month of birth ,13 To 14 Indicates the date of birth .

Input :

id_cards = ['310101199005052115', '320507199812280150']

Output :

310101199005052115:1990/05/05
320507199812280150:1998/12/28

Program code  

#!/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)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved