Question

Python Function: How to format phone number "9293827827" to "(929) 382-7827 in python. My code so...

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)

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program to input 6 numbers. After each number is input, print the biggest of...
Write a program to input 6 numbers. After each number is input, print the biggest of the numbers entered so far. Please use python and include a screenshot that the code is running. Please use simple code as I am only a high school student.
Write a python code to print (any given file) file as a csv format by using...
Write a python code to print (any given file) file as a csv format by using MRJob only. code must be able to run stand-alone MRJob application. For submission to your work: Your final hand should be a single file name BDM.py that takes exactly one arguments for the input path. output will be handled through redirection. Sample run: python BDM.py sample.csv > output.csv
i need this code to print a number of stars depending on how much the user...
i need this code to print a number of stars depending on how much the user wants and after * it prints no stars. if the user enters a negative number it should print "error invalid number" this is my code so far: def stars(n,i): stars(n, 1) if n <= 0: return "No stars" if i <= n: print("* ", end="") stars(n, i + 1) else: print("no stars") stars(n - 1, 1) n = int(input("enter an integer")) def main(): stars()...
How do I code these in Python? My final result should be "Monday 4" day =...
How do I code these in Python? My final result should be "Monday 4" day = Monday square = 2 ^ 2 print (square) print(day + square)
Write a python code that will ask the user to enter an integer number n. Construct...
Write a python code that will ask the user to enter an integer number n. Construct a recursive function that prints numbers 1 to n in the form “11223344..nn”.
python code Write the function definition for a function which accepts one value from the main...
python code Write the function definition for a function which accepts one value from the main program and prints three times the number that is sent to it. For example, if the program sent 8, the function would print 24.
Using the code as an example, explain why Python is a fixed format programming language. Describe...
Using the code as an example, explain why Python is a fixed format programming language. Describe what would be output for each of the print statements in the code listing.- Given the difference in output, explain the different roles of readLine(), readLines(), and read() functions. with open("rainfall.txt","r") as inFile:    aLine = inFile.readLine() with open("rainfall.txt", "r") as inFile:   lineList = inFile.readLines() with open("rainfall.txt", "r") as inFile:   fileString = inFile.read()) print(aLine) print(lineList) print(fileString)
How can I change my username so that the getuser Python output is different? I am...
How can I change my username so that the getuser Python output is different? I am using a windows pc import datetime import getpass print("\n\nFinished execution at ", datetime.datetime.now()) print(getpass.getuser())
Convert from Python to C++ how would this code be written in C++? def calculate(price,quantity): total=price*quantity...
Convert from Python to C++ how would this code be written in C++? def calculate(price,quantity): total=price*quantity if(quantity<10): discount=0 elif(quantity>=10 and quantity<=20): discount=total*10/100 elif(quantity>20): discount=total*20/100 #returning price after discount return total-discount    quantity=float(input("Enter quantity: ")) price=float(input("Enter price: ")) print("Price after discount is ${0:.2f}".format(calculate(price,quantity)))
3.plese to write the correct code: The code below will loop as long as the number...
3.plese to write the correct code: The code below will loop as long as the number that you enter isn’t negative. It will add each non negative number to the current sum. It will print out the sum and average of all of the numbers you have entered. But someone jumbled up the code. Can you reorganize and indent it so it works properly? count = count + 1 message = "Enter an integer or a negative number to stop"...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT