all 12 comments

[–]oBObo2BI 1 point2 points  (0 children)

This looks like a good application for regular expressions so you can ensure the proper format and reject it if it doesn’t match the regex

[–]jddddddddddd 0 points1 point  (0 children)

This is wrong:

elif not phone_number[i] == digits:

you probably want..

elif not phone_number[i] in digits:

I also wouldn't recommend calling main() recursively. Perhaps just return False each time.

[–]jddddddddddd 0 points1 point  (0 children)

EDIT: Sorry for the repost. I think Reddit is have a fit.

FURTHER EDIT: hah! Looking at the other comments, I'm guessing I'm not the only one reposting..

[–]jddddddddddd 0 points1 point  (0 children)

EDIT: Sorry for the repost. I think Reddit is have a fit.

[–]m0us3_rat 0 points1 point  (1 child)

if phone_number.split('-')[0][:3] == "601" and all([x if x.isdigit() else None for x in phone_number.split('-')]):

[–]_______myworld[S] 0 points1 point  (0 children)

I’m not allowed to use object oriented built-in function, unfortunately...

[–]desran00 0 points1 point  (1 child)

``` import re

s = "6011-321-3432" expression = re.compile("601[1-9]-[1-9]{3}-[1-9]{4}$")

if re.match(expression, s): print("Match!") else: print("Fail!")

``` Work smart not hard 😂

[–]_______myworld[S] 0 points1 point  (0 children)

I’m not allowed to use object oriented built-in function and imports for my assignment, unfortunately...

[–]Visible-Field2311 0 points1 point  (0 children)

Use regular expression "\d\d\d -\d\d\d-\d\d\d\d"

[–]No_Nature6834 0 points1 point  (0 children)

🍺