Python 练习实例4

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

#1 20160409
ymd = input(u'请输入年月日(格式20150218):')
yr = int(ymd[:4]); mo = int(ymd[4:6]); dy = int(ymd[6:])

day = [31,28,31,30,31,30,31,31,30,31,30,31]
days = dy
for i in range(len(day)+1):
    if i < mo - 1:
        days += day[i]

if yr // 4 == 0:
    days += 1

print(u'%s是%s年的第%d天。' %(ymd, yr, days))

还是在python2的环境,粘贴过来变成3

你可能感兴趣的:(python,实例)