Question: The functionality of my code is good, it's just not printing correctly the right things, could someone help me modify my code so that it

The functionality of my code is good, it's just not printing correctly the right things, could someone help me modify my code so that it does print it correctly alongside the sample output?
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_phone = start_number
end_phone = 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) is not None
or switchboards[end_area].get(start_area) is not None
):
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]:
if len(str(connected_area))==3:
print(f"\tTrunk line connection to: {connected_area}")
print("Local phone numbers are:")
for phone_number, connections in switchboards[switchboard].items():
if len(str(phone_number))==7:
if not connections:
print(f"\tPhone with number: {phone_number} is not in use.")
else:
for connection in connections:
print(f"\tPhone with number: {connection} is in use.")
print("
")
def display(switchboards):
for switchboard in switchboards:
display_switchboard(switchboards, switchboard)
Enter command: switch-add 443
Enter command: switch-add 410
Enter command: switch-add 656
Enter command: switch-connect 443410
Enter command: phone-add 656-112-3412
Enter command: phone-add 443-132-1332
switch-connect 656410
start-call 656-112-3412443-132-1332
Enter command: switch-connect 656410
Enter command: display
Switchboard with area code: 443
Trunk lines are:
Trunk line connection to: 410
Local phone numbers are:
Phone with number: 1321332 is connected to 656-1123412
Switchboard with area code: 410
Trunk lines are:
Trunk line connection to: 443
Trunk line connection to: 656
Local phone numbers are:
Switchboard with area code: 656
Trunk lines are:
Trunk line connection to: 410
Local phone numbers are:
Phone with number: 1123412 is connected to 443-1321332
After running the code, it does not look like this I believe, could someone help me on this?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!