Http://www.cnblogs.com/vamei/archive/2012/07/19/2600135.html
Python small topic for quick tutorial Job answer
Write a program to determine if 2008 is a leap year.
Write a program that calculates October 1, 2008 is the day of the year? (January 1, 2008 is the first day of the year)
1 #Judging Leap years2 defis_leap_year (year):3 return(year% 4 = = 0 andYear% 100! = 0)orYear% 400 = =04 #Judging is the day of the year5 defgetdayinyear (year,month,day):6Month_day = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]7 ifis_leap_year (year):8month_day[1]=299 returnSUM (month_day[:month-1]) + DayTen One Print(Getdayinyear (2008,1,1)) A Print(Getdayinyear (2008,10,1)) - Print(Getdayinyear (2009,10,1))
There are also ready-made methods for Time strftime () refer to this method description click Link http://www.runoob.com/python/att-time-strftime.html
Import datetime def Getdayinyear (year, Month, day): = Datetime.date (year, month, day) return date.strftime ('%j' )print(getdayinyear (2008,1,1))print(getdayinyear (2008,10,1)) Print(getdayinyear (2009,10,1))
Python judges leap Year, judging date is the day ordinal of the current