+ 1
Where is the mistake? В чем косяк?(Python)
Задача по проверке телефонных номеров. Код работает, но один из скрытых тестов завален. The task is to check the phone numbers. It works, but one of the closed tests is failed. import re num=input() pattern=r"^1|8|9\d{7}" if re.match(pattern, num):print('Valid') else:print('Invalid')
2 ответов
+ 4
your pattern gives this match:
12345678
^ ^
so only the first and last digit get matched. You can use an online regex tester to see what happens:
https://pythex.org/?regex=%5E1%7C8%7C9%5Cd%7B7%7D&test_string=12345678&ignorecase=0&multiline=0&dotall=0&verbose=0
Don't worry about the URL, it just leads to a pythex.org and shows the result of your pattern
+ 2
pattern = r'^[189]\d{7}#x27;