Automation and Artificial Intelligence
A script derives the next port number from an interface name. What does it print? interface = "Gi1/0/7" port = interface.split("/")[-1] print(int(port) + 1)
Show the answer
Correct answerD. 8
AWhy not this: The int() conversion makes the addition numeric rather than string concatenation.
BWhy not this: The extracted value is 7, but the print expression adds 1 after converting it to an integer.
CWhy not this: The numeric string converts successfully, so adding the integer 1 does not cause a type error.
DWhy this is right: The last split component is '7'; converting it to an integer and adding 1 produces 8.
Splitting on '/' and selecting index -1 extracts the string '7'; int() converts it to an integer, so adding 1 produces 8. The result is not 71 because the operation is numeric addition, not string concatenation.