Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

How do I solve

Answered: 1 week ago

Question

2 What can organisations do to improve employee utilisation?

Answered: 1 week ago

Question

4 When is it a good idea to use the external supply of labour?

Answered: 1 week ago

Question

3. What would you do now if you were Mel Fisher?

Answered: 1 week ago