Answered step by step
Verified Expert Solution
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 switchconnect. The endcall 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 phoneadd twice on different phone numbers with different area codes, then using phonecall, my output does say that the lines are not connected, but after using switchconnect on the area codes from the phoneadd, then using phonecall, 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'
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
startdsphone strstartnumber
endphone strendnumber
if startarea endarea:
switchboardsstartareasetdefaultstartphone, appendendphone
printfLocal call: startareastartphone and endareaendphone are now connected.
elif switchboardsstartareagetendarea or switchboardsendareagetstartarea:
if endarea not in switchboardsstartarea:
printfConnecting switchboards startarea and endarea
connectswitchboardsswitchboards startarea, endarea
switchboardsstartareastartphoneappendendphone
switchboardsendareaendphoneappendstartphone
printfLong distance call: startareastartphone and endareaendphone are now connected.
else:
printfCannot 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:
printfTrunk line connection to: connectedarea
printLocal phone numbers are:
for phonenumber, connections in switchboardsswitchboarditems:
if not connections:
printfPhone with number: phonenumber is not in use.
else:
for connection in connections:
printfPhone with number: connection is in use.
def displayswitchboards:
for switchboard in switchboards:
displayswitchboardswitchboards 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: switchadd
Enter command: switchadd
Enter command: switchadd
Enter command: display
Switchboard with area code:
Trunk lines are:
Local phone numbers are:
Switchboard with area code:
Trunk lines are:
Local phone numbers are:
Switchboard with area code:
Trunk lines are:
Local phone numbers are:
Enter command: switchconnect
Enter command: phoneadd
Enter command: phoneadd
Enter command: display
Switchboard with area code:
Trunk lines are:
Trunk line connection to:
Phone with number: is not in use.
Enter command: startcall
and were not connected
enter command: switchconnect
Enter command: startcall
and are now connected.
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