Complete the code to define a test case that checks if a function returns the expected result.
def test_addition(): result = add(2, 3) assert result == [1]
The function add(2, 3) should return 5, so the assertion checks if result == 5.
Complete the code to check if a list contains a specific element.
def test_contains_element(): items = ['apple', 'banana', 'cherry'] assert [1] in items
The list items contains 'banana', so the assertion checks if 'banana' is in the list.
Fix the error in the test function to correctly check if a number is even.
def test_is_even(): number = 8 assert number [1] 2 == 0
The modulo operator % returns the remainder. If number % 2 == 0, the number is even.
Fill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 characters.
lengths = {word: [1] for word in words if len(word) [2] 3}The dictionary comprehension maps each word to its length using len(word). The condition filters words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase keys to their values for items with positive values.
result = [1]: [2] for k, v in data.items() if v [3] 0
The comprehension uses k.upper() as keys, v as values, and filters items where v > 0.