# 判断哪年哪月有几天
"""
介绍:
普通闰年:公历年份是4的倍数,且不是100的倍数的,为闰年(如2004年、2020年等就是闰年)。
世纪闰年:公历年份是整百数的,必须是400的倍数才是闰年(如1900年不是闰年,2000年是闰年)。
平年与闰年的区别:闰年的2月是29天,而平年的2月是28天;闰年一年有366天,平年一年有365天。
知识点:
1、数据类型转换
2、while 循环语句
2、if/elif/else 条件语句
"""
while True:
# 带提示语输入赋值
year = float(input('请输入年份:'))
month = float(input('请输入月份:'))
# 重新输入
if year < 1 or month < 1 or month > 12 or year > int(year) or month > int(month):
print('输入有误!!!')
continue
# 数据类型转换
year = int(year)
month = int(month)
# 平年/闰年共有的月份
if month in [1, 3, 5, 7, 8, 10, 12]:
print('{}年/{:0>2}月,有31天' .format(year, month))
elif month in [4, 6, 9, 11]:
print('{}年/{:0>2}月,有30天'.format(year, month))
# 特殊的2月份,单独处理
elif month == 2:
# 判断是否为闰年,世纪闰年和普通闰年一起判断
if year % 400 or (year % 4 == 0 and year % 100 != 0):
print('{}年/{:0>2}月,有29天'.format(year, month))
else:
print('{}年/{:0>2}月,有28天'.format(year, month))
运行结果:



