zoukankan      html  css  js  c++  java
  • Python代码之计算你活了多少秒

    #-*- coding:utf-8 -*-
    def Live():
    """
    根据出生年月日计算活了多长时间
       关注微信公众号【黑客易先生】,关注了你就知道我活儿好
    """
    import time #导入时间模块
    b = input("请输入您的出生年月日,如(19950103):")
    for i in range (1,10): #程序循环执行10次
    a = time.time() #当前时间的时间戳
    x = time.mktime(time.strptime(b,'%Y%m%d')) #计算出生日的时间戳
    c = a - x #用当前时间戳减去出生日的时间戳,等于活了多久的时间戳
    m = c / 60
    h = m / 60
    d = h /24
    y = d / 365 #程序并不完美,因为未考虑闰年

    print ("您已经活了"" ", round(c),"秒"" ", int(m),"分钟"" ", int(h),"小时"" ", int(d),"天"" ", round(y,2),"年")
    #把活了多久的时间戳格式化打印
    time.sleep(10) #程序暂停十秒

  • 相关阅读:
    radio checkbox select
    easyui_tree
    MySQL编码问题
    Django shell调试
    encode,decode
    结束进程
    Django models 字段
    re
    (转)为Ubuntu安装翻译词典(星际译王)
    python3进阶之正则表达式之基本概念
  • 原文地址:https://www.cnblogs.com/yigongzi/p/6743103.html
Copyright © 2011-2022 走看看