I need help writing this Python program: When people enter phone numbers, they t
ID: 3690445 • Letter: I
Question
I need help writing this Python program:
When people enter phone numbers, they typically enter it in a few different formats:
(919)866-5555
919-866-5555
9198665555
Write a program to strip all occurrences of these characters: '(',') and '-'. Also, strip all the leading and trailing whitespace characters. Display the stripped phone number.
The following are a few examples:
Enter phone number: (919)866-5555
Phone number with extra characters stripped: 9198665555
Another example:
Enter phone number: 9198995555
Phone number with extra characters stripped: 9198665555
[Hint: to delete a string, you can replace it by an empty string]
Explanation / Answer
def validate(inp) :
l = ""
for i in inp :
if(i.isdigit()):
l = l+str(i)
print "Phone number with extra characters stripped:",l
inp = raw_input("Enter enter phone number : ")
inp = inp.strip()
inp = inp.strip("(-)")
validate(inp)