标签:date and run lse == input day 错误 print
# 用户输入八位日期 date = input(‘请输入八位年月日(如20180405):‘) # 分割年月日 day = int(date[-2:]) month = int(date[4:6]) year = int(date[:4]) print(year, month, day) # 定义闰年开关 if year % 4 == 0 and year % 100 != 100 or year % 400 == 0: print(‘%d年是闰年‘ % year) isRunNian = True else: print(‘%d不是闰年‘ % year) isRunNian = False # 判断是否是闰年 if isRunNian: # 判断月 if month in [x for x in range(1, 13)]: monthmaxd = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 判断日 if day <= monthmaxd[month]: print(‘有效日期‘) else: print(‘不是有效日期,日错误‘) else: print(‘不是有效日期,月错误‘) else: # 判断月 if month in [x for x in range(1, 13)]: monthmaxd = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 判断日 if day <= monthmaxd[month]: print(‘有效日期‘) else: print(‘不是有效日期,日错误‘) else: print(‘不是有效日期,月错误‘)
标签:date and run lse == input day 错误 print
原文地址:https://www.cnblogs.com/wf-skylark/p/9009697.html