300-435 · Question #98
Refer to the exhibit. The Python script fails. Which change enables the script to complete successfully?
The correct answer is B. Store set_interfaces() return value in interfaces var.. For the Python script to successfully use the output of set_interfaces(), its return value must be explicitly stored in the interfaces variable for subsequent operations.
Question
Exhibit
Options
- AThe interface object must be defined in the set_interfaces function.
- BStore set_interfaces() return value in interfaces var.
- CAn iterable object type must be used for the interfaces object.
- DThe interfaces object must be defined in the main function.
How the community answered
(39 responses)- A5% (2)
- B90% (35)
- C3% (1)
- D3% (1)
Why each option
For the Python script to successfully use the output of `set_interfaces()`, its return value must be explicitly stored in the `interfaces` variable for subsequent operations.
Defining the 'interface' object within 'set_interfaces' is the responsibility of that function, but the problem is likely about passing or receiving its output, not its internal definition.
The script likely fails because the 'set_interfaces()' function, which presumably generates or retrieves the 'interfaces' data, returns a value that is not assigned to the 'interfaces' variable. Without this assignment (e.g., 'interfaces = set_interfaces()'), the 'interfaces' variable remains undefined or holds an incorrect value for further processing, leading to script failure.
While 'interfaces' might need to be iterable for some operations, the fundamental issue is getting the data into the 'interfaces' variable in the first place, regardless of its type.
The 'interfaces' object doesn't necessarily have to be defined in the main function; it could be passed as an argument or defined in a higher scope, but the immediate problem is usually the uncaptured return value.
Concept tested: Python function return values and variable assignment
Source: https://docs.python.org/3/tutorial/controlflow.html#defining-functions
Topics
Community Discussion
No community discussion yet for this question.
