Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to calculate the ID card number with python

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to calculate the ID card number with python". In the operation of the actual case, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Analysis.

The ID card number exposed in the ticket is: 3302211993. The ID number is 4914, missing only four digits of the month and date. So that's 365 possibilities, because 1993 is not a leap year, there are only 365 days.

So let's first use python to generate all the dates for 1993:

All dates of birth def dateRange (year): fmt ='% Y-%m-%d'bgn = int (time.mktime (time.strptime (year+'-01-01, fmt) end = int (time.mktime (time.strptime (year+'-12-31), fmt)) list_date = [time.strftime (fmt, time.localtime (I) for i in range (bgn, end+1, 3600mm 24)] return [i.replace ('-') '') for i in list_date] data_time = dateRange ('1993') ['19930101,' 19930102, '19930103,' 19931229, '19931230,' 19931231']

Then verify the validity of the ID card number made up of these dates. You don't need to write your own code to verify the validity of your ID number. Here we recommend an encapsulated library called id-validator.

Installation:

Pip install id-validator

Use id-validator to verify the ID card number just generated in turn:

All dates of birth def dateRange (year): fmt ='% Y-%m-%d'bgn = int (time.mktime (time.strptime (year+'-01-01, fmt) end = int (time.mktime (time.strptime (year+'-12-31), fmt)) list_date = [time.strftime (fmt, time.localtime (I) for i in range (bgn, end+1, 3600mm 24)] return [i.replace ('-') '') for i in list_date] # iterate through all dates Print ID card number def vali_dator (id1, id2, id3): for i in dateRange (id2): theid = id1 + I + id3if validator.is_valid (theid): print (theid) vali_dator.

34 results were screened out.

330221199301064914330221199301144914330221199312134914330221199312214914 how to calculate ID card number with python is introduced here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report