0

Why it can't solve test n°4in ?

I'm stuck in this problem, phone number validator in python , this is my code import re #your code goes here pattern = r"^1|8|9 + [0-9]" num = input() if re.match(pattern , num) and len(num) == 8: print ("Valid") else: print ("Invalid") All test except the fourth one how can I pass

25th Feb 2021, 4:29 PM
Smile Sam
Smile Sam - avatar
4 Réponses
+ 3
# Smile Sam your modified code works well for me: import re #your code goes here pattern = r"^[189]\d{7}
quot; num = input() if re.match(pattern , num): print ("Valid") else: print ("Invalid")
25th Feb 2021, 6:25 PM
visph
visph - avatar
+ 2
pattern = r"^[189]\d{7}
quot; if re.match(pattern, num): ... # no need to check length outside of regexp: last $ mean string end, as ^ mean string start ;) # here is the minimal change needed: # pattern = r"(1|8|9)[0-9]+"
25th Feb 2021, 5:38 PM
visph
visph - avatar
0
Still the same problem does not work for me
25th Feb 2021, 6:10 PM
Smile Sam
Smile Sam - avatar
0
visph thanks It is working
25th Feb 2021, 6:30 PM
Smile Sam
Smile Sam - avatar