Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could someone modify my code to where after a series of inputs, when using end - call and it see that there's a trunk line

Could someone modify my code to where after a series of inputs, when using end-call and it see that there's a trunk line connection it outputs this:
Hanging up...
Connection Terminated.
but when there is no connection it displays something like this:
Unable to disconnect.
I will provide the code and the main function as a picture
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)
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_2

Step: 3

blur-text-image_3

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

Define success.

Answered: 1 week ago

Question

1 What is meant by systematic training?

Answered: 1 week ago