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

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()
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容