300-435 exam dumps

300-435 practice question 20 of 322

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

300-435 Question 20

Single answer

You are working on automating a network monitoring script using Python. The following script is provided:

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

def check_devices(devices):
    active_devices = []
    for device in devices:
        if device.status == 'up':
            active_devices.append(device.name)
    return active_devices

devices = [
    Device('Switch1', '192.168.1.1', 'up'),
    Device('Router1', '192.168.1.2', 'down'),
    Device('AP1', '192.168.1.3', 'up')
]

result = check_devices(devices)
print(result)

What will be the output of the script?

  1. A

    ['Switch1', 'Router1', 'AP1']

  2. B

    ['Switch1', 'AP1']

  3. C

    ['Router1']

  4. D

    []

Show answer and explanation

Correct answer: B

Explanation

The script defines a Device class and uses the check_devices function to iterate through a list of devices. It checks the status of each device, and if the status is 'up', it appends the device name to the active_devices list. The final result contains only the names of devices with a status of 'up', which in this case are 'Switch1' and 'AP1'.

  • A. Incorrect.

    Incorrect. This would include all devices regardless of their status. The script filters devices based on their status being 'up'.

  • B. Correct.

    Correct. The script checks the status of each device and only appends devices with a status of 'up' to the active_devices list. 'Switch1' and 'AP1' meet this condition.

  • C. Incorrect.

    Incorrect. 'Router1' has a status of 'down' and is not included in the active_devices list.

  • D. Incorrect.

    Incorrect. The script does return results, specifically devices with a status of 'up'. An empty result would only occur if no devices had a status of 'up'.

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