• python判断输入日期是该年的第几天


    1.输入日期,判断日期是该年度的第几天

      

    iyear = int(input("请输入年:
    "))
    imonth = int(input("请输入月:
    "))
    iday = int(input("请输入日:
    "))
    
    
    
    def checkYear(iyear):
        return ((iyear % 4 == 0 and iyear % 100 != 0) or iyear % 400 == 0)
    
    
    tol_day = 0
    
    for i in range(1, imonth):
        # tol_day+=lis[i]
        if i in [1, 3, 5, 7, 8, 10, 12]:
            tol_day += 31
        elif i == 2:
            tol_day += 28
            if checkYear(iyear):
                tol_day += 1
        else:
            tol_day += 30
    tol_day += iday
    print(tol_day)
    
    或者:
    lis = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    #如果是闰年的话,2月份加一天
    if checkYear(year):
        lis[2] += 1
    #遍历一次days,对应月份中的天数,把对应的天数传递给tol_day存储
    for i in range(month):
        tol_day+= lis[i]
    print(tol_day+iday)
    

    2..输入日期,判断日期距离现在是多少天

    #datetime 获取年月日
    import datetime
    datetime.datetime.now().year
    datetime.datetime.now().month
    datetime.datetime.now().day
    
    
    
    import datetime
    
    def func():
        y = input("请输入年份")
        m = input("请输入月份")
        d = input("请输入日期")
        t1 = datetime.datetime.now()#获取当前时间
        t2 = datetime.datetime(int(y),int(m),int(d))#获取指定时间
        t3 = t2 - t1
        print("离%s-%s-%s还有%d天"%(y,m,d,t3.days))
    func()
    

     3.打印以下内容:

    for i in range(9, 0, -1):
        for k in range(0, 9 - i):
            print("    ", end="	")
        for j in range(1, i + 1):
            print("{}*{}={:02d}".format(i, j, i * j), end="	")
        print()
    
    
    
    for i in range(1, 11):
        for j in range(1, 11):
            print(" * ", end="")
    
        print()
    
    
    print("---------------------------")
    for i in range(1, 11):
        for j in range(1, 11):
            if i == 1 or i == 10:
                print(" *  *  *  *  *  *  *  *  *  * ", end="")
                break
            elif  j == 1 or j == 10 :
                print(" * ", end="")
            else:
                print(" . ", end="")
        print()
    
    print("---------------------")
    
    for i in range(1, 11):
        for j in range(1, 11):
            if i == 1 or i == 10:
                print(" *  *  *  *  *  *  *  *  *  * ", end="")
                break
            elif i == j or j == 1 or j == 10 or (i + j == 11):
                print(" * ", end="")
            else:
                print("   ", end="")
        print()
    
    
    print("---------------------")
    
    for i in range(1, 11):
        for j in range(1, 11):
            if i == 1 or i == 10:
                print(" *  *  *  *  *  *  *  *  *  * ", end="")
                break
            elif i == j or j == 1 or j == 10 or (i + j == 11):
                print(" * ", end="")
            elif i <= j and j + i >= 11:
                print(" $ ", end="")
            else:
                print("   ", end="")
        print()
    

      

  • 相关阅读:
    Activator.CreateInstance 反射实例化对象
    MVC Form提交
    Redis 下载
    List<T> 序列化与反序列化
    快速反射DataTable
    数据库特性
    javascript判断文件大小
    MD5
    HttpHelper
    cacheHelper
  • 原文地址:https://www.cnblogs.com/songdanlee/p/11128961.html
Copyright © 2020-2023  润新知