python 根据年份,月份信息显示此月份天数
发布时间:2020-12-20 10:51:10 所属栏目:Python 来源:网络整理
导读: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
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,11): 15 return 30 16 else: 17 return 31 18 19 print(y_m(2004,12)) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |