python 输入年份月份 输出该月份的天数
# 获得输入
Datetime = input("please input a datatime (such as:201012): \n")
if len(Datetime)!=6:
print("-- input error , please input 6-bit digital --")
Datetime = input("please input again: \n")
# 切片附值 + str——>int
Years = int(Datetime[0:4])
Month = int(Datetime[4:6])
Day = 28
# 判断闰年
if Years%4==0 and Years%100!=0 or Years%400==0 :
if Month == 2:
Day = 29
# 普通月份
A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
if Month in A:
Day = 31
elif Month in B:
Day = 30
print("This month have {} day !".format(Day))