Answered step by step
Verified Expert Solution
Question
1 Approved Answer
After countless attempts to solve my issue and using chegg, I can not figure out why my code is not connecting my trunk lines correctly.
After countless attempts to solve my issue and using chegg, I can not figure out why my code is not connecting my trunk lines correctly. I will send the inputs, but my code is suppose to use recursion somewhere within my code but even with it i am still not getting the desired result. whenever i switchconnect phone numbers and startcall between them, it's suppose to say that the numbers are connected, but it's not. Could someone please help me fix my issue?
code:
import json
HYPHEN
QUIT 'quit'
SWITCHCONNECT 'switchconnect'
SWITCHADD 'switchadd'
PHONEADD 'phoneadd'
NETWORKSAVE 'networksave'
NETWORKLOAD 'networkload'
STARTCALL 'startcall'
ENDCALL 'endcall'
DISPLAY 'display'
def connectswitchboardsswitchboards area area:
if area not in switchboards:
switchboardsarea
if area not in switchboards:
switchboardsarea
switchboardsareaarea
switchboardsareaarea
def addswitchboardswitchboards areacode:
# Add a new switchboard to the network
switchboardsareacode
def addphoneswitchboards areacode, phonenumber:
# Add a new phone to the network
if areacode not in switchboards:
switchboardsareacode
switchboardsareacodephonenumber
def savenetworkswitchboards filename:
# Save the network to a file
with openfilename, w as f:
json.dumpswitchboards f
def loadnetworkfilename:
# Load the network from a file
with openfilename, r as f:
switchboards json.loadf
return switchboards
def startcallswitchboards startarea, startnumber, endarea, endnumber:
# Start a call between two phones
if startarea not in switchboards or endarea not in switchboards:
printInvalid area code.
return
startphone strstartnumber
endphone strendnumber
if startarea endarea:
# Local call
switchboardsstartareasetdefaultstartphone, appendendphone
printfstartareastartphone and endareaendphone are now connected.
elif switchboardsstartareagetendarea or switchboardsendareagetstartarea:
# Longdistance call
if endarea not in switchboardsstartarea:
printfConnecting switchboards startarea and endarea
connectswitchboardsswitchboards startarea, endarea
switchboardsstartareastartphoneappendendphone
printfstartareastartphone and endareaendphone are now connected.
else:
printfCannot connect phone startareastartphone to phone endareaendphone
def endcallswitchboards startarea, startnumber:
# End a call between two phones
if lenswitchboardsstartareastartnumber:
switchboardsstartareastartnumberpop
else:
printfNo call in progress for phone startnumber
def displayswitchboardswitchboards switchboard:
printSwitchboard with area code: strswitchboard
print Trunk lines are:
for connectedarea in switchboardsswitchboard:
print Trunk line connection to: strconnectedarea
print Local phone numbers are:
for phonenumber, connections in switchboardsswitchboarditems:
if not connections:
print Phone with number: strphonenumber is not in use.
else:
for connection in connections:
print Phone with number: strconnection is in use.
def displayswitchboards:
# Display the network
for switchboard in switchboards:
displayswitchboardswitchboards switchboard
inputs:
switchadd
switchadd
switchadd
display
switchconnect
phoneadd
phoneadd
display
startcall
switchconnect
startcall
main function will be sent as picture
The issue is after using startcall the first time, it's suppose to say that the phone lines are not connected, but using switchconnect is suppose to connect these numbers together to allow them to call, but within my code the issue is that it's not saying that it's 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