- 3
Even my output is shown as same as the expected output in result ,but it's shown incorrect ,why??
5 ответов
+ 1
Please don't post same question twice
https://www.sololearn.com/discuss/2807770/?ref=app
+ 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.
+ 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.
0
Can you share your codes ?
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")