我正在尝试测试用户输入,但它似乎只在第一次通过。如果我第一次给出正确的数据,它会起作用,但如果我最初给出错误的数据,然后在重新提示后使用正确的数据,它永远不会识别它是正确的。知道为什么它第一次起作用,但在那之后的任何时候都不起作用吗?这是代码,
testDate = open("Sales.txt")
def DateTest(Date, Position):
firstTry = True
validSyntax = False
Done = False
while Done == False:
while validSyntax == False:
if firstTry == True:
print "debug 2"
try:
Date = Date.strip().split(',')
Year = int(Date[0])
Month = int(Date[1])
Day = int(Date[2])
Date = (Year, Month, Day)
except:
print "That is invalid input."
firstTry = False
else:
validSyntax = True
print "ok got it"
elif firstTry == False:
NewDate = raw_input("Please input the desired %s date in the form YYYY,MM,DD: " % Position)
try :
NewDate = startDate.strip().split(',')
Year = int(NewDate[0])
Month = int(NewDate[1])
Day = int(NewDate[2])
NewDate = (Year, Month, Day)
except:
print "That is invalid input."
else:
validSyntax = True
print" ok got it"
if validSyntax == True:
for line in testDate:
line = line.strip().split(',')
yearTest = int(line[0])
monthTest = int(line[1])
dayTest = int(line[2])
dateTest = (yearTest, monthTest, dayTest)
if Year == yearTest:
if Month == monthTest:
if Day == dayTest:
Done = True
print "success"