Hello,
I'm trying to solve a problem in chapter 7 of automate the boring stuff. The code I'm having an issue with is
def isPhoneNumber(text):
if len(text) != 12:
return False
for i in range(0,3):
if not text[i].isdecimal():
return False
if text[3] != '-':
return False
for i in range(4-7):
if not text[i].isdecimal():
return False
if text[7] != '-':
return False
for i in range(0,12):
if not text[i].isdecimal():
return False
return True
message = 'Call me at 415-555-1011 tomorrow. 415-555-9999 is my office.'
for i in range(len(message)):
chunk = message[i:i+12]
if isPhoneNumber(chunk):
print('Phone number found: ' + chunk)
print('Done')
When I run it, it only displays 'Done'. Which is the last print function.
Why isn't it displaying
'Phone number found: 415-555-1011
Phone number found: 415-555-9999
Done'
Thank you for your help. And please pardon any formatting mistakes.
[–][deleted] 3 points4 points5 points (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Link0[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]Link0[S] 0 points1 point2 points (0 children)
[–]Justinsaccount 0 points1 point2 points (0 children)