当前位置:   article > 正文

python学习之根据身份证号判断所属省份、生日、性别、星座、生肖属相_python根据身份证号判断星座

python根据身份证号判断星座

通过个人身份证号码,利用python字符串分割和简单逻辑判断的方式,计算出所属省份、生日、性别、星座、生肖属相等信息。

这里直接贴代码了,喜欢的可以参考。具体归属地只做了省份,其他地市太多没做处理。

import math

lunar = '申酉戌亥子丑寅卯辰巳午未'
zodiac = '猴鸡狗猪鼠牛虎兔龙蛇马羊'
ztime = ['1936(1.24)', '1937(2.11)', '1938(1.31)', '1939(2.19)', '1940(2.08)', '1941(1.27)', '1942(2.15)', '1943(2.05)', '1944(1.25)', '1945(2.13)', '1946(2.02)', '1947(1.22)', '1948(2.10)', '1949(1.29)', '1950(2.17)', '1951(2.06)', '1952(1.27)', '1953(2.14)', '1954(2.03)', '1955(1.24)', '1956(2.12)', '1957(1.31)', '1958(2.18)', '1959(2.08)', '1960(1.28)', '1961(2.15)', '1962(2.05)', '1963(1.25)', '1964(2.13)', '1965(2.02)', '1966(1.21)', '1967(2.09)', '1968(1.30)', '1969(2.17)', '1970(2.06)', '1971(1.27)', '1972(2.15)', '1973(2.03)', '1974(1.23)', '1975(2.11)', '1976(1.31)', '1977(2.18)', '1978(2.07)', '1979(1.28)', '1980(2.16)', '1981(2.05)', '1982(1.25)', '1983(2.13)', '1984(2.2)', '1985(2.20)', '1986(2.09)', '1987(1.29)', '1988(2.17)', '1989(2.06)', '1990(1.27)', '1991(2.15)', '1992(2.04)', '1993(1.23)', '1994(2.10)', '1995(1.31)', '1996(2.19)', '1997(2.07)', '1998(1.28)', '1999(2.16)', '2000(2.05)', '2001(1.24)', '2002(2.12)', '2003(2.01)', '2004(1.22)', '2005(2.09)', '2006(1.29)', '2007(2.18)', '2008(2.07)', '2009(1.26)', '2010(2.14)', '2011(2.03)', '2012(1.23)', '2013(2.10)', '2014(2.04)', '2015(2.19)', '2016(2.08)', '2017(1.28)', '2018(2.16)', '2019(2.05)', '2020(1.25)', '2021(2.12)', '2022(2.01)', '2023(1.22)']
mdate = ''
ral = ['鼠',1984]
shop = '100000056303'
inside = ''
sdate=[20,19,21,20,21,22,23,23,23,24,23,22]     # 星座判断列表
conts =['摩羯座 ♑','水瓶座 ♒','双鱼座 ♓','白羊座 ♈','金牛座 ♉','双子座 ♊','巨蟹座 ♋','狮子座 ♌','处女座 ♍','天秤座 ♎','天蝎座 ♏','射手座 ♐','摩羯座 ♑']
signs=['♑','♒','♓','♈','♉','♊','♋','♌','♍','♎','♏','♐','♑']
dic={'11':'北京市','12':'天津市','13':'河北省','14':'山西省','15':'内蒙古自治区','22':'吉林省','23':'黑龙江省','31':'上海市',  '32':'江苏省','33':'浙江省','35':'福建省','36':'江西省','37':'山东省','41':'河南省','42':'湖北省','44':'广东省','45':'广西壮族自治区','46':'海南省','50':'重庆市','51':'四川省','53':'云南省','54':'西藏自治区','61':'陕西省','62':'甘肃省','63':'青海省','65':'新疆维吾尔自治区','71':'台湾省','81':'香港','82':'澳门'       }

def idget(str):
    newstr='' 
    if dic.get(str):
        newstr=dic[str]
    return newstr
def sign(cmonth,cdate):  #  判断星座函数
    if int(cdate)<sdate[int(cmonth)-1]:   # 如果日数据早于对应月列表中对应的日期
        print('你的星座是:' + conts[int(cmonth)-1])       # 直接输出星座列表对应月对应的星座
        #print(signs[int(cmonth)-1])       # 直接输出星座列表对应月对应的星座
    else:
        print('你的星座是:' + conts[int(cmonth)])         # 否则输出星座列表下一月对应的星座
        #print(signs[int(cmonth)])         # 否则输出星座列表下一月对应的星座
        
instr=input('请输入您的身份证号:\n')

if instr[:16].isdigit()and len(instr) == 18:
    print('你来自:',idget(instr[0:2]))
    print('你的生日是:' + instr[6:10] + '年' +instr [10:12] + '月' + instr[12:14] + '日')
    gender = '女' if int(instr[16]) % 2 == 0 else '男'
    print('你的性别是:' + gender )
    cyear = instr[6:10]     # 提取年数据
    cmonth=instr [10:12]    # 提取月数据
    cdate=instr[12:14]      # 提取日数据      
    sign(cmonth,cdate)      # 调用星座判断程序
    for item in ztime:
        if item[:4] == cyear:
            mdate = item[4:].strip(' ').strip('(').strip(')')
    ctime = str(cmonth) + str(cdate)
    ndate = mdate.split('.')
    smonth = ndate[0]
    sdate = ndate[1]
    stime = str(smonth) + str(sdate)
    if int(ctime) < int(stime):
        cyear = int(cyear) - 1
    rem = int(cyear) % 12
    print('要查询的属相是:' + zodiac[rem] + '\n属相对应的年份是:' + lunar[rem] + '年')
    

  • 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
  • 52
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/427147
推荐阅读
相关标签
  

闽ICP备14008679号