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

2nd Jan 2021, 8:22 AM
thandava krishna
thandava krishna - avatar
16 Respuestas
+ 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
2nd Jan 2021, 9:05 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 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
2nd Jan 2021, 8:57 AM
XXX
XXX - avatar
+ 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.
2nd Jan 2021, 9:08 AM
XXX
XXX - avatar
0
you can use (\d{7}) instead of [1-9]{7} and in line ‘5’ re.match
2nd Jan 2021, 9:07 AM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar
0
Zatch bell you are right
3rd Jan 2021, 12:48 PM
thandava krishna
thandava krishna - avatar
0
Not working
3rd Jan 2021, 12:52 PM
thandava krishna
thandava krishna - avatar
0
thandava krishna what's not working?
3rd Jan 2021, 12:52 PM
XXX
XXX - avatar
0
\d you suggested me to mention, i used it and it's not working.
3rd Jan 2021, 3:03 PM
thandava krishna
thandava krishna - avatar
0
thandava krishna it's working for me. What is the final pattern you used?
3rd Jan 2021, 3:15 PM
XXX
XXX - avatar
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
3rd Jan 2021, 5:46 PM
thandava krishna
thandava krishna - avatar
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.
3rd Jan 2021, 6:10 PM
XXX
XXX - avatar
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")
4th Jan 2021, 1:53 AM
thandava krishna
thandava krishna - avatar
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
4th Jan 2021, 2:52 AM
XXX
XXX - avatar
0
Thanks for the help, it worked XXX
4th Jan 2021, 3:47 AM
thandava krishna
thandava krishna - avatar
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?
4th Jan 2021, 3:48 AM
XXX
XXX - avatar
0
Yeah, i just read that again, and now i understood the logic. Thank you. yes it did work
4th Jan 2021, 3:57 AM
thandava krishna
thandava krishna - avatar