please create a simple python script for this exercise with an explanation of how it works. I have attached my starter code and desired outcome in the images. my starter # Program to simulate a speed dialer # Complete the four functions listed below that work with # two global lists that manage a dialer with 5 fixed slots. # Initialize the dialer with empty data. dialerNames = ["Empty", "Empty", "Empty", "Empty", "Empty"] dialerNumbers = ["Empty", "Empty", "Empty","Empty", "Empty"] #function to show the current dialer data def printList(): for i in range(len(dialerNames)): print((i + 1),dialerNames[i],dialerNumbers[i], sep="\t") #Function to handle dial by slot number command which # prompts the user for the slot number # validates the slot number # if not within valid range (1 through 5), prints "Invalid slot number" # if user enters non-integer input, prints "Please enter integer" using # try/except code block. # else checks if the slot at given slot number is empty, if so prints "Slot empty" # else prints "Calling name ........xxx-xxx-xxxx" # E.g. If user enters 3 and slot number 3 (values at index 2 in above lists) had # name = "Susan" and number 4255551212, this function will print # "Dialing Susan ........425-555-1212" def dialBySlot(): #Implement this function pass #Function to handle update by slot number command which # prompts the user for the slot number to be updated # if not within valid range, prints "Invalid slot number" # if user enters non-integer input, prints "Please enter integer" # using try/except code block. # else # prompts the user for the new name and new number # and updates entries for the slot number. # prints "Updated slot number X" where X is the slot number user entered. def updateSlot(): #Implement this function pass #Function to handle dial by name command which # prompts the user for the name # checks if the name is present in dialerNames list (make the comparison # case-insensitive) # if not present prints "Name not found." # else prints "Calling name ....xxx-xxx-xxxx" # E.g. If user enters "Susan" and slot number 3 (values at index 2 # in above lists) had name = "Susan" and number 4255551212, # dialByName() will print # "Dialing Susan ........425-555-1212" def dialByName(): #Implement this function pass def main(): print('''Welcome to the Speed Dialer. Commands: p for print \tn dial by name u for update\ts dial by slot e for exit''') command = input('''Please enter command(p/n/s/u/e): ''').lower() while (not command.startswith('e')): if (command.startswith('p')): printList() elif (command.startswith('n')): dialByName() elif (command.startswith('s')): dialBySlot() elif (command.startswith('u')): updateSlot() command = input("Please enter command(p/n/s/u/e): ").lower() print("Goodbye!") if __name__ == "__main__": main() You will complete a program that keeps track of a phone speed dialer directory which has 5 fixed slots. Your program will allow the user to see all the entries of the directory, and allow to dial and update an entry at a slot number. The 3 functions listed below and make sure the program runs as shown in the sample runs. Note that the functions are expected to work on the global lists, no need to pass them as arguments. dialBySlot: Function to handle dial by slot number command which prompts the user for the slot number and validates the slot number. If not within valid range (1 through 5), prints "Invalid slot number". If user enters non-integer input, prints "Please enter integer" using try/except code block. Otherwise checks if the slot at the given slot number is empty, if so prints "Slot empty" else prints "Calling name ........xxx-xxx-xxxx" E.g. If user enters 3 and slot number 3 (values at index 2 in above lists) had name = "Susan" and number 4255551212, this function will print "Dialing Susan .......425-555-1212". updateBySlot: Function to handle update by slot number command which prompts the user for the slot number to be updated. It next validates the slot number, if not within valid range, prints "Invalid slot number". If user enters non-integer input, prints "Please enter integer" using try/except code block. If valid, prompts the user for the new name and new number and updates entries in the two global lists for the slot number. It then prints "Updated slot number X" where X is the slot number user entered. dialByName: Function to handle dial by name command which prompts the user for the name. It then checks if the name is present in dialerNames list. (Make the name comparison case-insensitive). If not present, prints "Name not found." If present, prints "Calling name ....xxx-xxx-xxxx" E.g. If user enters "Susan" and slot number 3 (values at index 2 in above lists) had name = "Susan" and number 4255551212, dialByName() will print "Dialing Susan ........425-555-1212"
please create a simple python script for this exercise with an explanation of how it works. I have attached my starter code and desired outcome in the images.
my starter
# Program to simulate a speed dialer
# Complete the four functions listed below that work with
# two global lists that manage a dialer with 5 fixed slots.
# Initialize the dialer with empty data.
dialerNames = ["Empty", "Empty", "Empty", "Empty", "Empty"]
dialerNumbers = ["Empty", "Empty", "Empty","Empty", "Empty"]
#function to show the current dialer data
def printList():
for i in range(len(dialerNames)):
print((i + 1),dialerNames[i],dialerNumbers[i], sep="\t")
#Function to handle dial by slot number command which
# prompts the user for the slot number
# validates the slot number
# if not within valid range (1 through 5), prints "Invalid slot number"
# if user enters non-integer input, prints "Please enter integer" using
# try/except code block.
# else checks if the slot at given slot number is empty, if so prints "Slot empty"
# else prints "Calling name ........xxx-xxx-xxxx"
# E.g. If user enters 3 and slot number 3 (values at index 2 in above lists) had
# name = "Susan" and number 4255551212, this function will print
# "Dialing Susan ........425-555-1212"
def dialBySlot():
#Implement this function
pass
#Function to handle update by slot number command which
# prompts the user for the slot number to be updated
# if not within valid range, prints "Invalid slot number"
# if user enters non-integer input, prints "Please enter integer"
# using try/except code block.
# else
# prompts the user for the new name and new number
# and updates entries for the slot number.
# prints "Updated slot number X" where X is the slot number user entered.
def updateSlot():
#Implement this function
pass
#Function to handle dial by name command which
# prompts the user for the name
# checks if the name is present in dialerNames list (make the comparison
# case-insensitive)
# if not present prints "Name not found."
# else prints "Calling name ....xxx-xxx-xxxx"
# E.g. If user enters "Susan" and slot number 3 (values at index 2
# in above lists) had name = "Susan" and number 4255551212,
# dialByName() will print
# "Dialing Susan ........425-555-1212"
def dialByName():
#Implement this function
pass
def main():
print('''Welcome to the Speed Dialer.
Commands:
p for print \tn dial by name
u for update\ts dial by slot
e for exit''')
command = input('''Please enter command(p/n/s/u/e): ''').lower()
while (not command.startswith('e')):
if (command.startswith('p')):
printList()
elif (command.startswith('n')):
dialByName()
elif (command.startswith('s')):
dialBySlot()
elif (command.startswith('u')):
updateSlot()
command = input("Please enter command(p/n/s/u/e): ").lower()
print("Goodbye!")
if __name__ == "__main__":
main()
You will complete a program that keeps track of a phone speed dialer directory which has 5 fixed slots. Your program will allow the user to see all the entries of the directory, and allow to dial and update an entry at a slot number. The 3 functions listed below and make sure the program runs as shown in the sample runs. Note that the functions are expected to work on the global lists, no need to pass them as arguments.
dialBySlot: Function to handle dial by slot number command which prompts the user for the slot number and validates the slot number. If not within valid range (1 through 5), prints "Invalid slot number". If user enters non-integer input, prints "Please enter integer" using try/except code block. Otherwise checks if the slot at the given slot number is empty, if so prints "Slot empty" else prints "Calling name ........xxx-xxx-xxxx"
E.g. If user enters 3 and slot number 3 (values at index 2 in above lists) had name = "Susan" and number 4255551212, this function will print "Dialing Susan .......425-555-1212".
updateBySlot: Function to handle update by slot number command which prompts the user for the slot number to be updated. It next validates the slot number, if not within valid range, prints "Invalid slot number". If user enters non-integer input, prints "Please enter integer" using try/except code block. If valid, prompts the user for the new name and new number and updates entries in the two global lists for the slot number. It then prints "Updated slot number X" where X is the slot number user entered.
dialByName: Function to handle dial by name command which prompts the user for the name. It then checks if the name is present in dialerNames list. (Make the name comparison case-insensitive). If not present, prints "Name not found." If present, prints "Calling name ....xxx-xxx-xxxx"
E.g. If user enters "Susan" and slot number 3 (values at index 2 in above lists) had name = "Susan" and number 4255551212, dialByName() will print
"Dialing Susan ........425-555-1212"
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images