# -*- coding:cp936 -*- def daysInYear(): """ 题目:输入某年某月某日,判断这一天是这一年的第几天? 程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时需考虑多加一天。 """ yearth = int(raw_input('年份:')) month = int(raw_input('月份:')) dayth = int(raw_input('日期:')) print "日期是:%d年%d月%d日" % (yearth, month, dayth) sum = 0 days = {1:0,2:31,3:59,4:90,5:120,6:151,\ 7:181,8:212,9:243,10:273,11:304,12:334} sum += days[month] sum += dayth if month > 2: if yearth%400 == 0 or (yearth%4 == 0 and yearth%100 != 0): sum += 1 print "这一天是这一年的第%d天" % sum if (__name__ == '__main__'): daysInYear()