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
Question
Exhibits
Answer Area
Drag items
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
Community Discussion
No community discussion yet for this question.

