nerdexam
Cisco

350-401 · Question #769

Drag and Drop Question An engineer must create a script to append and modify device entries in a JSON-formatted file. The script must work as follows: Until interrupted from the keyboard, the script r

The correct answer is import json; while True:; except; File = open; File.close(). The correct sequence follows standard Python scripting logic: 'import json' must come first to load the JSON library, 'while True:' creates the infinite loop to continuously read device entries until interrupted, 'except' handles the KeyboardInterrupt exception when the user stop

Submitted by thandi_sa· Mar 6, 2026Network Automation and Programmability - specifically writing Python scripts to manipulate JSON-formatted data files, handle keyboard interrupts, and perform file I/O operations, aligning with Cisco CCNP/ENCOR or DevNet Associate exam objectives.

Question

Drag and Drop Question An engineer must create a script to append and modify device entries in a JSON-formatted file. The script must work as follows: Until interrupted from the keyboard, the script reads in the hostname of a device, its management IP address, operating system type, and CLI remote access protocol. After being interrupted, the script displays the entered entries and adds them to the JSON- formatted file, replacing existing entries whose hostname matches. The contents of the JSON-formatted file are as follows: Drag and drop the statements onto the blanks within the code to complete the script. Not all options are used. Answer:

Exhibits

350-401 question #769 exhibit 1
350-401 question #769 exhibit 2

Answer Area

Drag items

while True:exceptimport jsonFile.open()File.close()File = open

Correct arrangement

  • import json
  • while True:
  • except
  • File = open
  • File.close()

Explanation

The correct sequence follows standard Python scripting logic: 'import json' must come first to load the JSON library, 'while True:' creates the infinite loop to continuously read device entries until interrupted, 'except' handles the KeyboardInterrupt exception when the user stops the loop, 'File = open' is the correct Python syntax to open a file object (assigning it to a variable), and 'File.close()' properly closes the file after writing. This sequence reflects proper Python structure for reading input in a loop, catching interrupts, and performing file I/O operations.

Topics

#Python scripting#JSON file handling#exception handling#network automation

Community Discussion

No community discussion yet for this question.

Full 350-401 Practice