0
What's wrong with this code. Can anyone help me to fix it.
I wrote a code for an assignment after completion of lesson and every test case was successfully passed except one and it's asking to fix bugs and try again. Can anyone help me with this. https://code.sololearn.com/c1gn1Sh89HrX/?ref=app
16 Respostas
+ 4
I don't know what the question was.So I can't help you directly.But I can explain you what will your code do:
first your code will see the sequence:
whether the string starts with 1,8 or 9 if true.then if will check is there any number 1-9 for 7 times if it is it will return true to the condition else false.
An example of valid number:
12345678
An example of invalid number:
01233456
or
123456789
+ 3
In your pattern, after 1, 8 or 9 is found, you are matching 7 digits from range 1 till 9. But the 7 digits can have a 0 also. So instead of [1-9], use [0-9], or simply \d
+ 1
Zatch bell he most probably is talking about the 92nd part in the Python course, that is, the end of module project of the "Regular Expressions" section.
0
you can use (\d{7}) instead of [1-9]{7} and in line â5â re.match
0
Zatch bell you are right
0
Not working
0
thandava krishna
what's not working?
0
\d you suggested me to mention, i used it and it's not working.
0
thandava krishna
it's working for me. What is the final pattern you used?
0
Actually it's end of module project 92. For the code i wrote out of 5 test conditions 1 is showing failed and asking me to solve the bugs and try again. I can't see the reason because the test case was locked for pro version
0
thandava krishna
test cases are locked for everyone, not just for people who don't have pro. Anyways, can you please post the new again, which is failing so that I can tell what you are doing wrong. Because my solution worked for me.
0
import re
#your code goes here
phn = r"^[189][1-9](\d{7})quot;
num = input()
ph = re.search(phn, num)
if ph:
print ("Valid")
else:
print ("Invalid")
0
thandava krishna
Read my first answer again - "so INSTEAD of [1-9], use [0-9] or simply \d". Emphasis on 'instead of'. You need to remove the [1-9], and in its place, write \d
0
Thanks for the help, it worked XXX
0
thandava krishna
it's not written in the question that the numbers should be from 1-9, it can be 0 too. My solution worked for you?
0
Yeah, i just read that again, and now i understood the logic. Thank you.
yes it did work