0

"Python Core" Code project 91 - Phone Number Validator

In course "Python Core" Code project 91 - Phone Number Validator 2 variants of code behaves strangely at https://www.sololearn.com/learning/eom-project/1073/356 1 variant Code --------------------------------------------------------- import re #your code goes here pattern = r"\A[189][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\Z" if re.match(pattern, "57345672"): print ("Valid") else: print ("Invalid") --------------------------------------------------------- and 2 variant --------------------------------------------------------- import re #your code goes here pattern = r"[189]\d{7}

quot; if re.match(pattern, "57345672"): print ("Valid") else: print ("Invalid") --------------------------------------------------------- With Input 57345672 returns "Invalid" in IDLE (Python 3.9 64-bit) But at the site https://www.sololearn.com/learning/eom-project/1073/356 It is written that Your Output "Valid" And I've got info that someone checked the code and it works

24th Aug 2021, 9:41 PM
Dmitry Arkhangelsky
5 Réponses
+ 3
Yeah, it works fine. But for sololearn projects, you need to write a code that will work for any input not just that one value(57345672) if re.match(pattern, input())
25th Aug 2021, 7:05 AM
Simba
Simba - avatar
+ 2
import re num = input () pattern = r"^[1|8|9][0-9]*
quot; if re.match(pattern,num) and len(num)==8: print("Valid") else: print("Invalid")
19th Nov 2021, 3:06 PM
Stefan Bartl
Stefan Bartl - avatar
+ 1
It is written "Invalid" on my device in Sololearn.
25th Aug 2021, 4:02 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
Thank You very much Simba!
25th Aug 2021, 10:35 AM
Dmitry Arkhangelsky
0
Sorry for stupid coding 😩
25th Aug 2021, 9:45 PM
Dmitry Arkhangelsky