How do I rewrite this code so that when I print it the numbers come out like this (xxx)-xxx-xxxx or the picture, because everytime I print it comes out like this xxxxxxxxxx. def dialByName(names,numbers): '''Function to handle dial by name command which prompts the user for the name checks if the name is present in names list (make the comparison case-insensitive) if not present prints "Name not found." else prints "Calling name ....xxx-xxx-xxxx" E.g. If slot number 3 (values at index 2 in above lists) had name = "Susan" and number 4255551212, and user enters "susan" dialByName() will print "Calling Susan ........425-555-1212" ''' name = input('Enter the name: ') for i in range(len(names)): if names[i].lower() == name.lower(): print('Calling . . . . . . . .' + numbers[i]) break else: print('Name not found.')
How do I rewrite this code so that when I print it the numbers come out like this (xxx)-xxx-xxxx or the picture, because everytime I print it comes out like this xxxxxxxxxx.
def dialByName(names,numbers):
'''Function to handle dial by name command which
prompts the user for the name
checks if the name is present in names list (make the comparison
case-insensitive)
if not present prints "Name not found."
else prints "Calling name ....xxx-xxx-xxxx"
E.g. If slot number 3 (values at index 2 in above lists)
had name = "Susan" and number 4255551212, and user enters "susan"
dialByName() will print
"Calling Susan ........425-555-1212"
'''
name = input('Enter the name: ')
for i in range(len(names)):
if names[i].lower() == name.lower():
print('Calling . . . . . . . .' + numbers[i])
break
else:
print('Name not found.')
![2 IDLE Shell 3.9.2
File Edit Shell Debug Options Window Help
Welcome to the Speed Dialer.
Commands :
p for print
u for update
e for exit
n dial by name
s dial by slot
Please enter command (p/n/u/e) : p
Empty
Empty
Empty
Empty
Empty
Please enter command (p/n/u/e) : n
1
Empty
Empty
2
3
Empty
Empty
Empty
4
Enter the name: Molly
Name not found.
Please enter command (p/n/u/e) : u
Enter the slot number: 2
Enter new name: Molly
Enter ner
number: 4255551212
Updated slot number
Please enter command (p/n/u/e): p
1
Empty
Molly
Empty
Empty
Empty
Empty
2
4255551212
3
Empty
Empty
Empty
4
Please enter command (p/n/u/e): n
Enter the name: molly
Calling Molly...
Please enter command (p/n/u/e) : e
Goodbye!
>>> |
....425-555-1212
Ln: 35 Col: 4](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F40d615fe-416e-4ff3-b7c8-f99d7a371297%2F1f17c4de-1aeb-41f6-887a-5ee9b64c24b9%2Fn3br0n_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)