Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Within my code, I am suppose to use recursion somewhere there to ensure that it connects my trunk lines properly to allow phone calls and

Within my code, I am suppose to use recursion somewhere there to ensure that it connects my trunk lines properly to allow phone calls and I am ensure as to how I can do so and where. It is strongly reccomended I use recursion because any other solution, does not output my desired output. I am suppose to ensure that I have a trunk list for each area code then connect them when I call switch-connect. The end-call function is also suppose to disconnect the two numbers from each other.I have tried countless attempts on how to connect the two phone lines together and correctly display that they are connected. my desired output is that after using phone-add twice on 2 different phone numbers with 2 different area codes, then using phone-call, my output does say that the lines are not connected, but after using switch-connect on the 2 area codes from the phone-add, then using phone-call, it's suppose to say that the phone lines are now connected, but my code fails to show that. Can someone help me on this problem I can show you the code an
import json
QUIT = 'quit'
SWITCH_CONNECT = 'switch-connect'
SWITCH_ADD = 'switch-add'
PHONE_ADD = 'phone-add'
NETWORK_SAVE = 'network-save'
NETWORK_LOAD = 'network-load'
START_CALL = 'start-call'
END_CALL = 'end-call'
DISPLAY = 'display'
HYPHEN ='-'
def connect_switchboards(switchboards, area_1, area_2):
if area_1 not in switchboards:
switchboards[area_1]={}
if area_2 not in switchboards:
switchboards[area_2]={}
switchboards[area_1][area_2]={}
switchboards[area_2][area_1]={}
def add_switchboard(switchboards, area_code):
switchboards[area_code]={}
def add_phone(switchboards, area_code, phone_number):
if area_code not in switchboards:
switchboards[area_code]={}
switchboards[area_code][phone_number]=[]
def save_network(switchboards, file_name):
with open(file_name, 'w') as f:
json.dump(switchboards, f)
def load_network(file_name):
with open(file_name, 'r') as f:
switchboards = json.load(f)
return switchboards
def start_call(switchboards, start_area, start_number, end_area, end_number):
if start_area not in switchboards or end_area not in switchboards:
print('Invalid area code.')
return
start_dsphone str(start_number)
end_phone = str(end_number)
if start_area == end_area:
switchboards[start_area].setdefault(start_phone, []).append(end_phone)
print(f'Local call: {start_area}{start_phone} and {end_area}{end_phone} are now connected.')
elif switchboards[start_area].get(end_area) or switchboards[end_area].get(start_area):
if end_area not in switchboards[start_area]:
print(f'Connecting switchboards {start_area} and {end_area}.')
connect_switchboards(switchboards, start_area, end_area)
switchboards[start_area][start_phone].append(end_phone)
switchboards[end_area][end_phone].append(start_phone)
print(f'Long distance call: {start_area}{start_phone} and {end_area}{end_phone} are now connected.')
else:
print(f'Cannot connect phones: {start_area}{start_phone} to {end_area}{end_phone}.')
def end_call(switchboards, start_area, start_number):
if len(switchboards[start_area][start_number])>0:
switchboards[start_area][start_number].pop()
else:
print(f'No call in progress for phone {start_area}{start_number}.')
def display_switchboard(switchboards, switchboard):
print(f'Switchboard with area code: {switchboard}')
print('Trunk lines are:')
for connected_area in switchboards[switchboard]:
print(f'Trunk line connection to: {connected_area}')
print('Local phone numbers are:')
for phone_number, connections in switchboards[switchboard].items():
if not connections:
print(f'Phone with number: {phone_number} is not in use.')
else:
for connection in connections:
print(f'Phone with number: {connection} is in use.')
def display(switchboards):
for switchboard in switchboards:
display_switchboard(switchboards, switchboard)
(main code will be sent as a picture)
I will also provide the sample output of what is required if that will help.
Enter command: switch-add 443
Enter command: switch-add 410
Enter command: switch-add 656
Enter command: display
Switchboard with area code: 443
Trunk lines are:
Local phone numbers are:
Switchboard with area code: 410
Trunk lines are:
Local phone numbers are:
Switchboard with area code: 656
Trunk lines are:
Local phone numbers are:
Enter command: switch-connect 443410
Enter command: phone-add 656-112-3412
Enter command: phone-add 443-132-1332
Enter command: display
Switchboard with area code: 443
Trunk lines are:
Trunk line connection to: 410
Phone with number: 1123412 is not in use.
Enter command: start-call 656-112-3412443-132-1332
656-112-3412 and 443-132-1332 were not connected
enter command: switch-connect 656443
Enter command: start-call 656-112-3412443-132-1332
656-112-3412 and 443-132-1332 are now connected.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

Students also viewed these Databases questions

Question

2. Use different groups for different subjects.

Answered: 1 week ago