美文网首页
python计算传入的日期是这一年的第几天

python计算传入的日期是这一年的第几天

作者: 以我丶之姓 | 来源:发表于2021-02-24 16:06 被阅读0次
    import sys
    def is_leap_year(year):
        return year % 4 == 0 and year %100 != 0 or year % 400 ==0
    # print(is_leap_year(2000))
    def which_day(year, month, date):
        days_of_month = [
            [31,28,31,30,31,30,31,31,30,31,30,31],
            [31,29,31,30,31,30,31,31,30,31,30,31]
            ][is_leap_year(year)]
        # print(days_of_month)
        total = 0
        for index in range(month - 1):
            total += days_of_month[index]
        
        return total + date
    def main():
        s = input('请输入年月日,以逗号隔开:')
        # print(type(s))
        # print(s.split(','))
        f = which_day(int(s.split(',')[0]),int(s.split(',')[1]),int(s.split(',')[2]))
        print(f)
    
    if __name__ == "__main__":
        main()
    

    相关文章

      网友评论

          本文标题:python计算传入的日期是这一年的第几天

          本文链接:https://www.haomeiwen.com/subject/yupsfltx.html