'''
设计者:ISDF
版本:v3..0
日期:04/01/2019
'''
'''
设计者:ISDF
版本:v4..0
日期:03/27/2024
'''
import datetime
#闰年判断函数
def ys_leep_year(year):
ys_leep = False
if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
ys_leep = True
return ys_leep
def main():
input_date_string = input("请输入日期(yyyy/mm/dd):")
date = datetime.datetime.strptime(input_date_string,"%Y/%m/%d")
# input(date)
year = date.year
month = date.month
day = date.day
days=0
days += day
#计算之前当前月份的天数总和
days_in_month_dict= {1:31,2:28,3:31,4:30,5:31,6:30,
7:31,8:31,9:30,10:31,11:30,12:31}
if ys_leep_year(year):
days_in_month_dict[2] = 29
i = 1
for i in range(1,month):
days += days_in_month_dict[i]
# days = sum(days_in_month)[:month - 1]) + day
print("这是第{}天".format(days))
if __name__ == '__main__':
main()
运行结果: