zoukankan      html  css  js  c++  java
  • python计算年龄小程序

    import time

    now = time.strftime('%Y%m%d',time.localtime(time.time()))
    bday = input("insert birthday example:20170101:")
    def getDays( year, month ):
    day = 31
    while day:
    try:
    time.strptime( '%s-%s-%d'%( year, month, day ), '%Y-%m-%d' )
    return day
    except:
    day -= 1

    mons = list(range(1,13))
    if (bday[4]) == '0':
    monn = bday[5:6]
    else:
    monn = bday[4:6]

    if (now[4]) == '0':
    mon_now = now[5:6]
    else:
    mon_now = now[4:6]

    youxm = mons[int(monn):int(mon_now)-1]
    monns = 0
    if (int(now[0:4]) - int(bday[0:4])) == 0:
    for monss in youxm:
    monns = int(monns) + int(getDays(int(bday[0:4]), int(monss)))
    monns = int(getDays(int(bday[0:4]), int(monn))) -int(bday[6:9]) + int(now[6:9]) + 1 +monns
    elif (int(now[0:4]) - int(bday[0:4])) == 1:
    youxm = mons[int(monn):13]
    for monss in youxm:
    monns = int(monns) + int(getDays(int(bday[0:4]), int(monss)))
    monns = monns + int(getDays(int(bday[0:4]), int(monn))) -int(bday[6:9])+1
    youxm = mons[0:int(mon_now)-1]
    for monns_now in youxm:
    monns = int(monns) + int(getDays(int(now[0:4]), int(monns_now)))
    monns = monns + int(now[6:9])
    else:
    youxms = list(range(int(bday[0:4])+1,int(now[0:4])))
    monns = 0
    for youxm in youxms:
    for monsz in mons:
    monns = int(monns) + int(getDays(int(youxm), int(monsz)))
    youxm = mons[int(monn):13]
    for monss in youxm:
    monns = int(monns) + int(getDays(int(bday[0:4]), int(monss)))
    monns = monns + int(getDays(int(bday[0:4]), int(monn))) -int(bday[6:9])+1
    youxm = mons[0:int(mon_now)-1]
    for monns_now in youxm:
    monns = int(monns) + int(getDays(int(now[0:4]), int(monns_now)))
    monns = monns + int(now[6:9])
    year = monns//365
    days = monns%365
    if monns < 365*5:
    print('宝宝年龄是' + str(year) + '岁' + str(days) + '天')
    else:
    print('您的年龄是'+str(year)+'岁'+str(days)+'天')


    #大家 多交流为了我们的明天,交流QQ149951292
  • 相关阅读:
    JNDI
    在Tomcat上发布JNDI资源
    使用数据库连接池配置数据源
    JDBC连接数据库
    数据库中的一些概念
    线程池和数据库连接池
    springmvc学习指南 之---第25篇 Spring Bean有三种配置方式
    springmvc学习指南 之---第24篇 国际化问题
    深入刨析tomcat 之---第23篇 聊一下web容器的filter配置和defaultservet
    又一本springmvc学习指南 之---第22篇 springmvc 加载.xml文件的bean标签的过程
  • 原文地址:https://www.cnblogs.com/hmysql/p/7809977.html
Copyright © 2011-2022 走看看