- 3

Even my output is shown as same as the expected output in result ,but it's shown incorrect ,why??

9th Jun 2021, 8:37 AM
Md Shakil
Md Shakil - avatar
5 ответов
+ 1
Please don't post same question twice https://www.sololearn.com/discuss/2807770/?ref=app
9th Jun 2021, 9:28 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 1
1. You're using an incorrect pattern. Don't use a OR'ed group for the 1st digit, but use a class with the 3 valid options instead. The second part, [0-9], is ok, but you could just as easily use \d instead. You don't want to use +, but instead you want to make sure that the second part is true exactly 7 times! Then also make sure it is the end of the pattern $, the beginning ^ doesn't matter as much as changing to the class will take care of it, but you can leave it if you'd like. 2. Once your pattern is correct, you'll just need to check if there is a match. No need to check the length.
9th Jun 2021, 9:34 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Only thing the reason of incorrect of my code i that i write "valid " instead of "Valid " and "invalid" instead of "Invalid " After this i got the correct result.
9th Jun 2021, 9:45 AM
Md Shakil
Md Shakil - avatar
0
Can you share your codes ?
9th Jun 2021, 8:43 AM
TOLUENE
TOLUENE - avatar
0
import re pattern = r"^(1|8|9)[0-9]+" a = input() if len(a)==8: if re.match(pattern,a): print ("valid") else : print ("invalid") else: print ("invalid")
9th Jun 2021, 8:52 AM
Md Shakil
Md Shakil - avatar