
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))
这个程序哪里错 展开
# 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))
这个程序哪里错 展开
展开全部
稍微改动了一下》》》》
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))
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询