zoukankan      html  css  js  c++  java
  • 函数判断输入日期是这年的第几天

    rmonth = [0, 31, 29, 31, 30, 31, 30, 31,31, 30, 31, 30, 31]
    month = [0, 31, 28, 31, 30, 31, 30, 31,31, 30, 31, 30, 31]
    days = 0
    def  pd_days(y, m, d):
        global rmonth, month, days
        # 判断闰年
        if y % 4 == 0 and y % 100 != 0 or y % 400 == 0:
            print('%s年是闰年' % y)
            # 判断月
            if m in range(1,13):
                # 判断日
                if d <= rmonth[m]:
                    for i in range(m):
                        days += rmonth[i]
                    days += d
                else:
                    print('日错误')
            else:
                print('月错误')
        else:
            print('%s年不是闰年' % y)
            # 判断月
            if m in range(1, 13):
                # 判断日
                if d <= month[m]:
                    for i in range(m):
                        days += month[i]
                    days += d
                else:
                    print('日错误')
            else:
                print('月错误')
        return days
    
    day = input('请输入八位年月日(如20080808):')
    y = int(day[:4])
    m = int(day[4:6])
    d = int(day[6:])
    print('您输入的是 %d 年 %d 月 %d 日' % (y, m, d))
    print('此日是%d年的第%d天!' % (y, pd_days(y, m, d)))
    

      

                                                                       -------  知识无价,汗水有情,如需搬运请注明出处,谢谢!

  • 相关阅读:
    Find the Smallest K Elements in an Array
    Count of Smaller Number
    Number of Inversion Couple
    Delete False Elements
    Sort Array
    Tree Diameter
    Segment Tree Implementation
    Java Programming Mock Tests
    zz Morris Traversal方法遍历二叉树(非递归,不用栈,O(1)空间)
    Algorithm about SubArrays & SubStrings
  • 原文地址:https://www.cnblogs.com/wf-skylark/p/9009792.html
Copyright © 2011-2022 走看看