DevNet Associate Module 1 Quiz – Python Review (Answers)

DevNet Associate Module 1 Quiz – Python Review (Answers)

1. A student is learning Python using the interactive interpreter mode. The student issues the commands:

>>> routers=[]
>>> switches=[]
>>> devices=[\"RT1\", \"RT2\", \"RT3\", SW1\", \"SW2\", \"SW3\"]
>>> devices=devices + [\"RT4\", \"SW4\"]
>>> for i in devices:
if \"R\" in i:
routers.append(i)
else: switches.append(i)
>>> switches

What is the result?

  • [‘SW4’, ‘SW3’, ‘SW2’, ‘SW1’]
  • [‘SW1’, ‘SW2’, ‘SW3’]
  • [‘SW4’, ‘SW1’, ‘SW2’, ‘SW3’]
  • [‘SW4’]
  • [‘SW1’, ‘SW2’, ‘SW3’, ‘SW4’]

Explanation: In Python, two lists can be concatenated by using the + (plus sign) operator. The second list appends to the first list and makes a new list. The Python for function is used to loop through the elements in a list and perform an operation on an element. The if statement can be used within the for function to determine the proper action based on the matching condition of each element.

2. A student is learning Python in the interactive interpreter mode. The student issues the commands:

>>> devicenames=[\"RT1\", \"RT2\", \"SW1\", \"SW2\"]
>>> devicenames[-1]

What is the result?

  • [‘RT2’, ‘SW1’, ‘SW2’]
  • SW1
  • RT1
  • SW2
  • an error message

Explanation: In Python, an item in a list can be referenced and manipulated using its index. The first item in a list is indexed as zero, the second is indexed as one, and so on. The last item can also be referenced with an index of [-1].

3. A developer needs to check the version of the running Python package. Which command should the developer use?

  • python3 -i
  • python3 -q
  • python3 –v
  • python3 -V

Explanation: The command python3 starts Python, but adding the -V option displays the specific version being used. 

4. A student is learning Python in the interactive interpreter mode. The student issues the command:

>>> type(True)

What is the data type reported by Python?

  • Boolean
  • integer
  • string
  • float

Explanation: A type of True or False is a predefined value of the Boolean data type.

5. Which Python programming function is used to display output?

  • if
  • for
  • print
  • while

Explanation: Print is used to display output in a Python programing language interpreter.


Related Articles

guest
0 Comments
Inline Feedbacks
View all comments