Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote