nerdexam
Cisco

300-435 · Question #18

Refer to the exhibit. The task is to create a Python script to display an alert message when a Meraki Not-Security Appliance goes down. The exhibit shows sample data that is received. Which Python…

The correct answer is C. print("The Switch: "+return_val['device Name']+", went down at: "+return_val['occurredAt']+"). To access values in a Python dictionary representing JSON data, you must use bracket notation with string keys to retrieve specific field values.

Network Automation Foundation

Question

Refer to the exhibit. The task is to create a Python script to display an alert message when a Meraki Not-Security Appliance goes down. The exhibit shows sample data that is received. Which Python snippet displays the device name and the time at which the switch went down?

Exhibits

300-435 question #18 exhibit 1
300-435 question #18 exhibit 2

Options

  • Awith return_val: print("The Switch: "+deviceName+", went down at: "+occurredAt)
  • Bprint("The Switch: "+return_val.deviceName+", went down at: "+return_val.occurredAt)
  • Cprint("The Switch: "+return_val['device Name']+", went down at: "+return_val['occurredAt']+")
  • Dwith items as return_val: print("The Switch: "+items.deviceName+", went down at: "+items.occurredAt)

How the community answered

(37 responses)
  • A
    3% (1)
  • C
    92% (34)
  • D
    5% (2)

Why each option

To access values in a Python dictionary representing JSON data, you must use bracket notation with string keys to retrieve specific field values.

Awith return_val: print("The Switch: "+deviceName+", went down at: "+occurredAt)

This syntax is incorrect for accessing dictionary values; `with return_val:` is for context managers, and `deviceName` and `occurredAt` would be undefined variables in this scope without explicit assignment.

Bprint("The Switch: "+return_val.deviceName+", went down at: "+return_val.occurredAt)

Python dictionaries do not allow attribute-style access (e.g., `return_val.deviceName`); this dot notation is typically used for object attributes, not dictionary keys.

Cprint("The Switch: "+return_val['device Name']+", went down at: "+return_val['occurredAt']+")Correct

When JSON data is parsed into a Python dictionary (like `return_val`), values are accessed using their string keys with bracket notation, such as `return_val['deviceName']` and `return_val['occurredAt']`. This correctly extracts the required device name and time from the dictionary.

Dwith items as return_val: print("The Switch: "+items.deviceName+", went down at: "+items.occurredAt)

The `with items as return_val:` syntax is syntactically incorrect for iterating or assigning dictionary values in this context and `items.deviceName` would still be an invalid way to access dictionary elements.

Concept tested: Python dictionary access and JSON parsing

Source: https://docs.python.org/3/tutorial/datastructures.html#dictionaries

Topics

#Python Dictionaries#String Formatting#Data Parsing#API Data Handling

Community Discussion

No community discussion yet for this question.

Full 300-435 Practice