1 # conventional method 2 year = int (INPUT ( ' Enter year: ' )) . 3 month The int = (INPUT ( ' Enter the month (1 ~ 12 is): ' )) . 4 IF month The == 2 : . 5 IF year% == 0. 4 and year 0 = 100%! or year 400% == 0: . 6 Print ( ' leap year 29 days ' ) . 7 the else : . 8 Print ( ' average year 28 days ' ) . 9 10 elif month The in(4,6,9,11 ): . 11 Print ( " 30 days " ) 12 is the else : 13 is Print ( ' 31 is days ' )
1 # Method two: function method 2 DEF Y_M (year, month The): . 3 '' ' . 4 according to the year, month information shows number of days this month . 5 : param year: Enter Year: . 6 : param month The: Please enter the month (1 to 12 is): . 7 : return: the number of days . 8 '' ' . 9 IF month The> 12 is or month The <= 0: 10 return -1 . 11 IF month The == 2 : 12 is return 29 IF year. 4% 0 == and ! = 100% year 0 or year 400% == 0 the else 28 13 is 14 if month in (4, 6, 9, 11): 15 return 30 16 else: 17 return 31 18 19 print(y_m(2004,12))