我正在尝试验证我的python脚本:
def DOBSearch():
loop = True
while loop == True:
try:
DOBsrch = int(input("Please enter the birth month in a two digit format e.g. 02: "))
for row in BkRdr:
DOB = row[6]
day,month,year = DOB.split("/")
if DOBsrch == int(month):
print("W")
surname = row[0]
firstname = row[1]
print(firstname, " ",surname)
addrsBk.close
loop = False
else:
print("1 That was an invalid choice please try again.")
except:
print("That was an invalid choice please try again.")
然而,当我尝试测试脚本时,我发现存在错误/错误,因为我得到以下输出:
Please enter the birth month in a two digit format e.g. 02: ergase
That was an invalid choice please try again.
Please enter the birth month in a two digit format e.g. 02: 34
1 That was an invalid choice please try again.
1 That was an invalid choice please try again.
1 That was an invalid choice please try again.
1 That was an invalid choice please try again.
1 That was an invalid choice please try again.
1 That was an invalid choice please try again.
Please enter the birth month in a two digit format e.g. 02: 234567
Please enter the birth month in a two digit format e.g. 02: 02
Please enter the birth month in a two digit format e.g. 02: 02
Please enter the birth month in a two digit format e.g. 02: 02
Please enter the birth month in a two digit format e.g. 02:
这是CSV文件:
Jackson,Samantha,2 Heather Row,Basingstoke,RG21 3SD,01256 135434,23/04/1973,sam.jackson@hotmail.com
Vickers,Jonathan,18 Saville Gardens,Reading,RG3 5FH,01196 678254,04/02/1965,the_man@btinternet.com
Morris,Sally,The Old Lodge, Hook,RG23 5RD,01256 728443,19/02/1975,smorris@fgh.co.uk
Cobbly,Harry,345 The High Street,Guildford,GU2 4KJ,01458 288763,30/03/1960,harry.cobbly@somewhere.org.uk
Khan,Jasmine,36 Hever Avenue,Edenbridge,TN34 4FG,01569 276524,28/02/1980,jas.khan@hotmail.com
Vickers,Harriet,45 Sage Gardens,Brighton,BN3 2FG,01675 662554,04/04/1968,harriet.vickers@btinternet.com