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.')

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education