Please help me i don't know why this doesn't work. i think group 1 in varnumpattern doesn't work properly | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please help me i don't know why this doesn't work. i think group 1 in varnumpattern doesn't work properly

""" You are given a number input, and need to check if it is a valid phone number. A valid phone number has exactly 8 digits and starts with 1, 8 or 9. Output "Valid" if the number is valid and "Invalid", if it is not. """ import re possiblevnum = input() vnumpattern = r"(1|8|9)(\d.......)?" num_matching = re.match(vnumpattern, possiblevnum) """ the reason i added isinstance is because if i didn't, after the first number, you could input letters along with numbers that would still count as valid """ if num_matching and isinstance(possiblevnum, int): print('Valid') else: print('Invalid')

4th Nov 2021, 8:53 PM
ozzy
ozzy - avatar
5 Answers
+ 2
vnumpattern = r"[189]\d{7}
quot; if num_matching:
4th Nov 2021, 9:29 PM
Solo
Solo - avatar
+ 1
try it now
5th Nov 2021, 8:55 AM
Solo
Solo - avatar
0
i am not sure why, but it worked for all of them except test case 3. i cannot view what the input is so i don't know. thank you for the response though.
5th Nov 2021, 6:53 AM
ozzy
ozzy - avatar
0
nvm i found out what the problem was
5th Nov 2021, 7:47 AM
ozzy
ozzy - avatar
0
Yeah what you edited was the solution I found as well. Thanks for the help. Your original response helped me find the correct answer still.
12th Nov 2021, 5:38 PM
ozzy
ozzy - avatar