1 #!/usr/bin/env/python32 #-*-codinf:utf-8-*-3 #year:20184 #day:1385 #- xx/xx6 #year:20007 #day:638 #- 03/039 #year:2014Ten #day:63 One #- 03/04 A defis_leap_year (year): - ifYear% 100! =0: - ifYear% 4 = =0: the return1 - Else: - ifYear% 400 = =0: - return1 + return0 - + defGet_days_by_year_month (year,month): ADays = [# Geneva, Geneva, the at[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], -[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], - ] - returnDays[is_leap_year (year)][month-1] - - defget_month_day_by_year_days (year, days): inmonth, day = 1, 1 - ### to whileTrue: +D =Get_days_by_year_month (year, month) - ifDays <=D: theDay = Days * Break $Days-=DPanax NotoginsengMonth + = 1 - ### the + returnMonth, Day A defGet_days_by_year_month_day (year, Month, day): the #2018/3/18-31+28+18 +Days = Day - forIinchRange (1, month): $Days + =Get_days_by_year_month (year, i) $ return Days - - if __name__=='__main__': theyear = Int (input ('Year :')) -month = Int (input ('Month:'))Wuyiday = Int (input ('Day :')) theDays =Get_days_by_year_month_day (year, month, day) - Print('%d/%02d/%02d-%dday (s) in%d year.'%(year, month, day, days, year)) Wudays = Int (input ('Day :')) -month, day =get_month_day_by_year_days (year, days) About Print('%d of%d --%02d/%02d'% (days, year, month, day))
Execution Result:
You can query the number of days from the beginning of 2018 to the specified date, or you can query the date in days
year:2018
Month:5
Day:27
2018/05/27-147day (s) in 2018 year.
day:148
148 of 2018--05/28
python--Calendar