0
In course "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"4 ответов
0
It's "1" or "8" or "9":
[1|8|9]
0
Thanks for your wise advice Simon, sorry for stupid mistake
0
There's nothing stupid about this. It takes time to memorise these things.
0
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")