python年、月情報によるこの月の日数

4662 ワード

 1 #     
 2 year = int(input(''))
 3 month = int(input('     (1~12):'))
 4 if month == 2:
 5     if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
 6         print('  29 ')
 7     else:
 8         print('  28 ')
 9 
10 elif month in (4,6,9,11):
11     print('30 ')
12 else:
13     print('31 ')
 1 #
 2 def y_m(year, month):
 3     '''
 4  5     :param year:      :
 6     :param month:      (1~12):
 7     :return:   
 8     '''
 9     if month >12 or month <= 0:
10         return -1
11     if month == 2:
12         return 29 if year % 4 == 0 and year % 100 != 0 or year % 400 == 0 else 28
13 
14     if month in (4, 6, 9, 11):
15         return 30
16     else:
17         return 31
18 
19 print(y_m(2004,12))

 
転載先:https://www.cnblogs.com/xiaoliangliu86/p/11423197.html