Question

Python Code

Scrubbing and reformatting data is a real world problem in computer science, it is the process of taking in a human input that may be in the incorrect format and cleaning it up to put it in a standard format. How can I write a program that asks someone to enter a phone number and then returns that phone number in a standard format if possible otherwise giving an error.

Examples:

Please enter a phone number including area code: 607-8675309

(607)867-5309

Please enter a phone number including area code: 16078675309

(607)867-5309

Please enter a phone number including area code: (607) Jenny I got your number, I need to make you mine, Jenny don't change your number, 8675309

(607)867-5309

Était-ce utile?

La solution 2

I would suggest to cleanup/validate phone number formatting using regular expressions.

Autres conseils

You need to clean the input fields and check against your desired output and return the a message accordingly. Python web frameworks like Django, Web2py, Flask exists to precisely help with these types of problems.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top