python遇到问题了

#Thisisaprogramthatacceptsadateintheformmonth/day/year#andoutputswhetherornotthedatei... # This is a program that accepts a date in the form month/day/year
# and outputs whether or not the date is valid.
x=raw_input("Please enter the date:")
import re
def date(x):
L=[1,3,5,7,8,10,12]
L1=list(range(1,12))
L2=list(range(1,31))
y=list(map(int,re.sub('month/day/year','/',x).split()))
N=y[2]
if y[0]==2:
if N%400==0 or (N%4==0 and N%100!=0):
if y[1] in L2[:28]:
return True
else:
return False
else:
if y[1] in L2[:27]:
return True
else:
return False
else:
if y[0] in L and y[0] in L1 and y[1] in L2:
return True
elif y[0] not in L and y[0] in L1 and y[1] in L2[:29]:
return True
else:
return False
print(date(x))
这个程序哪里错
展开
 我来答
sunhk_25
2014-10-20 · TA获得超过1123个赞
知道小有建树答主
回答量:497
采纳率:50%
帮助的人:372万
展开全部

稍微改动了一下》》》》

x=raw_input("Please enter the date:")
import re
def date(x):
    L=[1,3,5,7,8,10,12]
    #L1=list(range(1,12))
    #L2=list(range(1,31))
    #y=list(map(int,re.sub('month/day/year','/',x).split()))
    L1=list(range(1,13))
    L2=list(range(1,32))
    y = list(map(int,x.split("/")))
    if len(y)!=3:
        return False;
        
    
    N=y[2]
    if y[0]==2:
       if N%400==0 or (N%4==0 and N%100!=0):
           if y[1] in L2[:28]:
               return True
           else:
               return False
       else:
           if y[1] in L2[:27]:
               return True
           else:
               return False
    else:
        if y[0] in L and y[0] in L1 and y[1] in L2:
            return True
        elif y[0] not in L and y[0] in L1 and y[1] in L2[:29]:
            return True
        else:
            return False
print(date(x))
更多追问追答
追问

运行之后就是错的

追答

月份天数长度都有问题,正规表达式也改了一下

x=raw_input("Please enter the date:")
import re
def date(x):
    L=[1,3,5,7,8,10,12]
    #L1=list(range(1,12))
    #L2=list(range(1,31))
    #y=list(map(int,re.sub('month/day/year','/',x).split()))
    L1=list(range(1,13))
    L2=list(range(1,32))
    y = list(map(int,x.split("/")))
    if len(y)!=3:
        return False;
        
    
    N=y[2]
    if y[0]==2:
       if N%400==0 or (N%4==0 and N%100!=0):
           if y[1] in L2[:29]:
               return True
           else:
               return False
       else:
           if y[1] in L2[:28]:
               return True
           else:
               return False
    else:
        if y[0] in L and y[0] in L1 and y[1] in L2:
            return True
        elif y[0] not in L and y[0] in L1 and y[1] in L2[:30]:
            return True
        else:
            return False
print(date(x))
yycgis
2014-10-20 · TA获得超过8267个赞
知道大有可为答主
回答量:6831
采纳率:63%
帮助的人:1723万
展开全部
你好:
有点长哦,你是用来干什么的?
追问
作业。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式