Parse Phone Number Digits
Python
Medium
3 views
Problem Description
A phone number string is provided. Extract only digits and output them. If there are no digits, output INVALID.
Input Format
One line string.
Output Format
Digits string or INVALID.
Official Solution
import sys
s=sys.stdin.read()
d=[]
for ch in s:
o=ord(ch)
if 48<=o<=57:
d.append(ch)
if not d:
sys.stdout.write('INVALID')
else:
sys.stdout.write(''.join(d))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!