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.')
Step by step
Solved in 2 steps with 2 images