300-435 exam dumps

300-435 practice question 24 of 322

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

300-435 Question 24

Single answer

You are working with a Python script to automate network configurations on a Cisco device. The script contains the following code snippet:

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

    def is_reachable(self):
        if self.ip_address.startswith('192.'):
            return True
        return False

    def display_info(self):
        print(f"Device {self.hostname} has IP address {self.ip_address}")

# Create a list of devices
devices = [
    Device('Router1', '192.168.1.1'),
    Device('Switch1', '10.1.1.1'),
    Device('Firewall1', '192.168.2.1')
]

for device in devices:
    if device.is_reachable():
        device.display_info()

What will be the output of the above script?

  1. A

    Device Router1 has IP address 192.168.1.1 Device Firewall1 has IP address 192.168.2.1

  2. B

    Device Router1 has IP address 192.168.1.1 Device Switch1 has IP address 10.1.1.1 Device Firewall1 has IP address 192.168.2.1

  3. C

    Device Switch1 has IP address 10.1.1.1

  4. D

    The script will throw an error because the 'is_reachable' method is not implemented correctly.

Show answer and explanation

Correct answer: A

Explanation

The script iterates over a list of Device objects and calls the is_reachable method to check if the IP address starts with '192.'. For devices that meet this condition, their information is displayed using the display_info method. Router1 and Firewall1 satisfy this condition, so their details are printed.

  • A. Correct.

    Correct - The is_reachable method checks if the IP address starts with '192.', so only Router1 and Firewall1 meet this condition. Their information is printed using the display_info method.

  • B. Incorrect.

    Incorrect - Switch1's IP address does not start with '192.', so it is not reachable, and its information will not be displayed.

  • C. Incorrect.

    Incorrect - Only Switch1's information is mentioned in this option, but the script includes multiple devices. Switch1 is also not reachable because its IP address does not start with '192.'.

  • D. Incorrect.

    Incorrect - The script will not throw any errors. The is_reachable method is correctly implemented and checks the condition using startswith.

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