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 works5 Answers
+ 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())
+ 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")
+ 1
It is written "Invalid" on my device in Sololearn.
+ 1
Thank You very much Simba!
0
Sorry for stupid coding đ©