help please | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

help please

Im in the python core's project "Phone Number Validator",there are 5 cases and i completed 4 but the number 3 gives me an error and its the only one and i dont know what should be the answer because its block.If someone could help me please. Here is my code: import re numero=str(input()) patron=r"^[1|8|9]" if re.match(patron,numero): print("Valid") else: print("Invalid")

5th Mar 2021, 8:08 PM
Yami Francø
Yami Francø - avatar
16 Answers
+ 2
#check this out # fix ur pattern and combine ur conditions 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")
6th Mar 2021, 12:06 AM
iTech
iTech - avatar
+ 2
Oh right that idea pass over my mind but im too lazy to code it
5th Mar 2021, 8:33 PM
Yami Francø
Yami Francø - avatar
+ 1
*I'm proud of you, sorry 😁 (my translator is naughty)
5th Mar 2021, 8:53 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Oh ok,thank you very much im gonna check that error
5th Mar 2021, 8:54 PM
Yami Francø
Yami Francø - avatar
+ 1
import re string=input() pattern=r"[\1|8|9](\d{7})" match=re.match(pattern,string) if match: print("Valid") else: print("Invalid")
6th Mar 2021, 1:54 PM
Evg-san
Evg-san - avatar
0
Hi! You check phone number by only 8 symbols?
5th Mar 2021, 8:29 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
😆 And I'm just busy working on your brilliant code right now 😉
5th Mar 2021, 8:35 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Oh thanks you didnt have to.Anyway i added the the 8 number's checker but it still given me error but the other are good.
5th Mar 2021, 8:43 PM
Yami Francø
Yami Francø - avatar
0
and how do you perform the verification?
5th Mar 2021, 8:45 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
like this: import re numero=str(input()) patron=r"^[1|8|9]" if len(numero)>=8: if re.match(patron,numero): print("Valid") else: print("Invalid") else: print("Invalid")
5th Mar 2021, 8:47 PM
Yami Francø
Yami Francø - avatar
0
you have an error in the comparison operator. be careful! But on the whole, I'm good for you!
5th Mar 2021, 8:51 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Oh thank you very much evg-san,now i have to figure it out how your code works.But i dont realize yet why my code doesnt work yet
6th Mar 2021, 8:59 PM
Yami Francø
Yami Francø - avatar
0
Thank yu very much Itech you make me understand that i have to combine and use more conditions
6th Mar 2021, 9:03 PM
Yami Francø
Yami Francø - avatar
0
u welcome. when u need help, u can inbox me, i will reply ASAP.
6th Mar 2021, 9:08 PM
iTech
iTech - avatar
0
from re import match as k if k(r"[189]\d{7}
quot;, input()): print("Valid") else: print("Invalid") """ Hope this helps; passes all the test cases. The 3rd test case ends with a non-digit. Including the dollar sign solves that """
7th Mar 2021, 12:24 PM
Calvin Thomas
Calvin Thomas - avatar
- 2
This is my variant in one string: ...check = len() if re.match() and check == 8: ...
5th Mar 2021, 8:59 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar