Python Function:
How to format phone number "9293827827" to "(929) 382-7827 in python.
My code so far:
phone_number = input("Enter phone number (numbers only): ")
phone_number_formatted = ??????
print(phone_number_formatted)
Python code:
#accepting phone number
phone_number=input("Enter phone number (numbers only): ")
#formating the phone_number by using slicing and concatenating each
slice in the required format
phone_number_formatted='('+phone_number[:3]+')'+"
"+phone_number[3:6]+'-'+phone_number[6:]
#printing the formatted phone number
print(phone_number_formatted)
Screenshot:
Input and Output:
Get Answers For Free
Most questions answered within 1 hours.