Python每日练习—2020.2.21

python每日练习—今天是第几天?

【问题描述】 输入某年某月某日,判断这一天是这一年的第几天?
【程序分析】 注意特殊情况,闰年时需要考虑二月多加一天
代码实现:

def isleapyear(year):
    return (year%400 == 0 or (year%4 == 0 and year/100 != 0))
DofM = [0,31,28,31,30,31,30,31,31,30,31,30]
res = 0
year = int(input('Year:'))
month = int(input('Month:'))
day = int(input('day:'))
if isleapyear(year):
    DofM[2] += 1
for i in range(month):
    res += DofM[i]
print(res+day)
全部评论

相关推荐

06-26 15:35
武汉大学 运营
点赞 评论 收藏
分享
牛客38347925...:9,2学生暑期实习失利开始投小厂,给这群人整自信了
点赞 评论 收藏
分享
06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务