foundNumber = False,倒数2行的变量foundNumber根据语境应该是True,但没有赋值True
def isPhoneNumber(text):if len(text) != 12:
return False
for i in range(0, 3):
if not text.isdecimal():
return False
if text != '-':
return False
for i in range(4, 7):
if not text.isdecimal():
return False
if text != '-':
return False
for i in range(8, 12):
if not text.isdecimal():
return False
return True
message = 'Call me at 415-555-1011 tomorrow. 415-555-9999 is my office.'
foundNumber = False
for i in range(len(message)):
chunk = message
if isPhoneNumber(chunk):
print('Phone number found: ' + chunk)
foundNumber = True
if not foundNumber:
print('Could not find any phone numbers.')
有人吗? Boibot 发表于 2022-5-19 01:18
有人吗?
我在最后一行加上 print(foundNumber) 后打印 True,成功赋值了:
页:
[1]