In Python When people enter phone numbers, they typically enter it in a few diff
ID: 3691397 • Letter: I
Question
In Python
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
Enter phone number: 919-866-5555
Phone number with extra characters stripped: 9198665555
Enter phone number: 9198665555
Phone number with extra characters stripped: 9198665555
[Hint: to delete a string, you can replace it by an empty string]
Explanation / Answer
# your code goes here
str = raw_input("Enter Phone Number: ")
print str
str = str.replace("(","");
str = str.replace(")","");
str = str.replace("-","");
str = str.replace(" ","");
print "Phone number with extra characters stripped: "
print str
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.