标签:python
输入某年某月某日,判断这一天是这一年的第几天?
#!/usr/bin/env python # -*- coding:utf -8 year = int(raw_input("输入年份: ")) month = int(raw_input("输入月份: ")) day = int(raw_input("输入日子: ")) months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334] if 0 < month <= 12: sum = months[month - 1] else: print "data error" sum += day leap = 0 if (year % 400 ==0) or ((year % 4 == 0) and (year % 100 != 0)): leap = 1 if(leap == 1) and (month > 2): sum += 1 print "it is the %dth day." % sum
[root@lianxi1 lianxi]# python e1.py 输入年份: 2015 输入月份: 6 输入日子: 7 it is the 158th day.
本文出自 “自定义” 博客,谢绝转载!
标签:python
原文地址:http://zidingyi.blog.51cto.com/10735263/1860855