Complete the code to define a simple unit test method using Python's unittest framework.
import unittest class TestMath(unittest.TestCase): def test_addition(self): self.assertEqual(2 + 3, [1])
The sum of 2 + 3 is 5, so the assertion should check for 5.
Complete the code to run all unit tests when the script is executed directly.
if __name__ == '__main__': [1]()
Calling unittest.main() runs all tests defined in the script.
Fix the error in the test method to correctly check if a list contains an element.
def test_contains(self): items = ['apple', 'banana', 'cherry'] self.assertTrue([1] in items)
To check if 'banana' is in the list, it must be a string literal with quotes.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
lengths = {word: [1] for word in words if [2]The dictionary maps each word to its length using len(word). The condition filters words with length greater than 3.
Fill all three blanks to create a test that asserts a dictionary comprehension filters positive values correctly.
result = [1]([2]: [3] for [2] in data if data[[2]] > 0)
The dict() function creates a dictionary from key-value pairs. 'k' is used as the key variable, and data[k] as the value. The comprehension filters keys with positive values.