nerdexam
Cisco

200-901 · Question #415

Drag and Drop Question Drag and drop the code from the bottom onto the box where the code is missing to complete the error path scenario. Not all options are used. Answer:

The correct answer is application/xml; iana-if-type:ethernetCsmacd; iana-if-type:ethernetCsmacd; iana-if-type:softwareLoopback. This drag-and-drop question tests Python class design, pytest unit testing for error paths, and conditional logic by requiring the test-taker to complete a Player class and its associated test suite.

Software Development and Design

Question

Drag and Drop Question Drag and drop the code from the bottom onto the box where the code is missing to complete the error path scenario. Not all options are used. Answer:

Exhibit

200-901 question #415 exhibit

Answer Area

Drag items

application/xmliana-if-type:softwareLoopbackrun_functioniana-if-type:ethernetCsmacd

Correct arrangement

  • application/xml
  • iana-if-type:ethernetCsmacd
  • iana-if-type:ethernetCsmacd
  • iana-if-type:softwareLoopback

Explanation

This drag-and-drop question tests Python class design, pytest unit testing for error paths, and conditional logic by requiring the test-taker to complete a Player class and its associated test suite.

Approach. 1. Blank in Player.__init__(self, name): The __init__ method should initialize all instance attributes. Since rating is not passed as an argument to __init__, it should be initialized to a default value. Drag self.rating = None to this blank. This is a common practice for attributes that may not have a value immediately. 2. Blank in set_rating(self, rating) (the primary if condition leading to raise ValueError): The provided pytest tests (test_add_higher_rating with 101 and test_add_lower_rating with -1) indicate that ratings outside the 1-100 range are invalid. Drag if rating < 1 or rating > 100: to this blank. This condition correctly identifies ratings that should raise a ValueError. The second image explicitly shows this as the correct fill. 3. Blank in set_rating(self, rating) (within the else block after the error condition): This else block is executed when rating is valid (between 1 and 100, inclusive). The second image explicitly shows if rating != 0: as the correct fill for this blank. Although this condition is redundant if the previous check rating < 1 has passed, and the method does not actually set self.rating, we must follow the explicit solution shown in the 'Answer Area' image. 4. Blank in test_add_invalid_rating (player.set_rating(...)): This test expects a ValueError to be raised. Given the if rating < 1 or rating > 100: validation, 0 is an invalid rating (0 < 1). Drag player.set_rating(0) to this blank. This will trigger the ValueError as expected by pytest.raises(). The second image confirms this placement.

Common mistakes.

  • common_mistake. A common mistake is selecting player.set_rating(85) for the test_add_invalid_rating blank. 85 is a valid rating according to the 1 <= rating <= 100 range, and therefore, it would not raise a ValueError. This would cause the pytest.raises(ValueError) context manager to fail the test. Another potential mistake is attempting to place self.rating = rating in the else block of set_rating where if rating != 0: is shown in the solution. While self.rating = rating would be more functionally appropriate for a set_rating method, the provided 'Answer Area' in the second image clearly indicates if rating != 0: as the intended solution for that specific blank in this problem's context. Misinterpreting the if/else structure or ignoring the explicit fills in the 'Answer Area' image would also lead to incorrect choices.

Concept tested. Python class definition, instance attribute initialization, method implementation, conditional logic (if/else), exception handling (raise ValueError), and unit testing with pytest for expected exceptions (pytest.raises).

Topics

#Error Handling#Exception Handling#Python#Software Development

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice