Answered step by step
Verified Expert Solution
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"
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
Enter command: switchadd
Enter command: switchadd
Enter command: switchadd
Enter command: switchconnect
Enter command: phoneadd
Enter command: phoneadd
switchconnect
startcall
Enter command: switchconnect
Enter command: display
Switchboard with area code:
Trunk lines are:
Trunk line connection to:
Local phone numbers are:
Phone with number: is connected to
Switchboard with area code:
Trunk lines are:
Trunk line connection to:
Trunk line connection to:
Local phone numbers are:
Switchboard with area code:
Trunk lines are:
Trunk line connection to:
Local phone numbers are:
Phone with number: is connected to
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
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