300-435 exam dumps

300-435 practice question 21 of 322

Automating Cisco Enterprise Solutions. Professional level, Cisco. Free question with the correct answer and a full explanation.

300-435 Question 21

Single answer

You are tasked with automating a network inventory system. Below is a Python script snippet that processes device information. What will be the output of this script?

class Device:
    def __init__(self, hostname, ip, status):
        self.hostname = hostname
        self.ip = ip
        self.status = status

def get_active_devices(devices):
    active_devices = []
    for device in devices:
        if device.status == 'active':
            active_devices.append(device.hostname)
    return active_devices

devices = [
    Device('Router1', '192.168.1.1', 'active'),
    Device('Switch1', '192.168.1.2', 'inactive'),
    Device('Firewall1', '192.168.1.3', 'active')
]

print(get_active_devices(devices))
  1. A

    ['Router1', 'Switch1', 'Firewall1']

  2. B

    ['Router1', 'Firewall1']

  3. C

    ['192.168.1.1', '192.168.1.3']

  4. D

    ['Switch1']

Show answer and explanation

Correct answer: B

Explanation

The Python script defines a class Device and a function get_active_devices that filters devices with 'active' status. The for loop iterates through the devices list, and the condition if device.status == 'active' ensures that only devices with 'active' status are added to the active_devices list. Based on the input, only 'Router1' and 'Firewall1' meet this condition, so the output is ['Router1', 'Firewall1'].

  • A. Incorrect.

    This is incorrect because not all devices are 'active'. Only 'Router1' and 'Firewall1' meet the condition of having a status of 'active'.

  • B. Correct.

    This is correct because the script filters devices based on their 'status' attribute and only appends the 'hostname' of devices with 'active' status to the list.

  • C. Incorrect.

    This is incorrect because the script appends the 'hostname', not the 'IP', of devices with 'active' status to the output list.

  • D. Incorrect.

    This is incorrect because 'Switch1' has a status of 'inactive', so it will not be included in the output list.

Timed practice exam

Take a 300-435 practice test under exam conditions

75 questions in 120 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam