Answered step by step
Verified Expert Solution
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 endcall 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"
SWITCHCONNECT "switchconnect"
SWITCHADD "switchadd"
PHONEADD "phoneadd"
NETWORKSAVE "networksave"
NETWORKLOAD "networkload"
STARTCALL "startcall"
ENDCALL "endcall"
DISPLAY "display"
HYPHEN
def connectswitchboardsswitchboards area area:
if area not in switchboards:
switchboardsarea
if area not in switchboards:
switchboardsarea
switchboardsareaarea
switchboardsareaarea
def addswitchboardswitchboards areacode:
switchboardsareacode
def addphoneswitchboards areacode, phonenumber:
if areacode not in switchboards:
switchboardsareacode
switchboardsareacodephonenumber
def savenetworkswitchboards filename:
with openfilename, w as f:
json.dumpswitchboards f
def loadnetworkfilename:
with openfilename, r as f:
switchboards json.loadf
return switchboards
def startcallswitchboards startarea, startnumber, endarea, endnumber:
if startarea not in switchboards or endarea not in switchboards:
printInvalid area code."
return
startphone startnumber
endphone endnumber
if startarea endarea:
switchboardsstartareasetdefaultstartphone, appendendphone
print
fLocal call: startareastartphone and endareaendphone are now connected."
elif
switchboardsstartareagetendarea is not None
or switchboardsendareagetstartarea is not None
:
if endarea not in switchboardsstartarea:
printfConnecting switchboards startarea and endarea
connectswitchboardsswitchboards startarea, endarea
switchboardsstartareastartphoneappendendphone
switchboardsendareaendphoneappendstartphone
print
fLong distance call: startareastartphone and endareaendphone are now connected."
else:
print
fCannot connect phones: startareastartphone to endareaendphone
def endcallswitchboards startarea, startnumber:
if lenswitchboardsstartareastartnumber:
switchboardsstartareastartnumberpop
else:
printfNo call in progress for phone startareastartnumber
def displayswitchboardswitchboards switchboard:
printfSwitchboard with area code: switchboard
printTrunk lines are:"
for connectedarea in switchboardsswitchboard:
if lenstrconnectedarea:
printftTrunk line connection to: connectedarea
printLocal phone numbers are:"
for phonenumber, connections in switchboardsswitchboarditems:
if lenstrphonenumber:
if not connections:
printftPhone with number: phonenumber is not in use."
else:
for connection in connections:
printftPhone with number: connection is in use."
print
def displayswitchboards:
for switchboard in switchboards:
displayswitchboardswitchboards switchboard
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started