PYTHON您好,check_date 代码返回 False - 编码有什么问题?第一个函数检查输入的月份中有多少天,第二个函数检查日期格式是否正确。'''def days_in_month(month):if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:return month == 31 else: return 30'''''' def check_date(date): day = int(date[0:2]) month = int(date[2:4]) year = date[4:6] if ( (day<=days_in_month(month)) and (0<month<13) ): return True else: return False''' print(check_date('011297'))
1 回答
陪伴而非守候
TA贡献1757条经验 获得超8个赞
您的错误在第 3 行:
def days_in_month(month):
if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:
return 31
else: return 30
def check_date(date):
day = int(date[0:2])
month = int(date[2:4])
year = date[4:6]
if ( (day<=days_in_month(month)) and (0<month<13) ):
return True
else:
return False
print(check_date('011297'))
添加回答
举报
0/150
提交
取消