def is_leap_year(year): |
"""判断是否为闰年""" |
if year % 4 = = 0 : |
if year % 100 = = 0 : |
if year % 400 = = 0 : |
return True |
else : |
return False |
else : |
return True |
else : |
return False |
def day_of_year(year, month, day): |
"""计算日期是该年份的第几天""" |
days_in_month = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] |
if is_leap_year(year): |
days_in_month[ 1 ] = 29 |
total_days = sum (days_in_month[:month - 1 ]) + day |
return total_days |
# 输入年月日 |
year = int ( input ( "请输入年份:" )) |
month = int ( input ( "请输入月份:" )) |
day = int ( input ( "请输入日期:" )) |
# 判断是否为闰年 |
leap_year = is_leap_year(year) |
if leap_year: |
print (f "{year}年是闰年" ) |
else : |
print (f "{year}年不是闰年" ) |
# 计算日期是该年份的第几天 |
day_of_year = day_of_year(year, month, day) |
print (f "{year}年的第{day_of_year}天" ) |