Python入门练习(Question4)

yizhihongxing

年份天数

题目

输入某年某月某日,判断这一天是这一年的第几天?

特殊情况,闰年时需考虑二月多加一天

解答

year = int(input("input year: "))
month = int(input("input month: "))
day = int(input("input day: "))
monthDays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]


def solution4(y, m, d):
if y % 4 == 0:
monthDays[2] = 29
index = 0
for m in range(m):
index += monthDays[m]
index += d
return index


print(solution4(year, month, day))

运行

Python入门练习(Question4)

 

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Python入门练习(Question4) - Python技术站

(0)
上一篇 2023年4月2日
下一篇 2023年4月2日
合作推广
合作推广
分享本页
返回顶部