Complete the code to write a simple test that checks if 2 + 2 equals 4 using assert.
def test_sum(): assert 2 + 2 [1] 4
The assert statement checks if the expression is True. Here, 2 + 2 == 4 must be True for the test to pass.
Complete the code to assert that a list contains the number 5.
def test_contains(): numbers = [1, 3, 5, 7] assert [1] in numbers
The assert checks if 5 is in the list numbers. This must be True for the test to pass.
Fix the error in the assert statement to correctly check if the string 'hello' starts with 'h'.
def test_startswith(): word = 'hello' assert word.[1]('h')
The correct method name is startswith. It returns True if the string starts with the given substring.
Fill both blanks to create a test that asserts the length of the list is greater than 3.
def test_length(): items = [1, 2, 3, 4, 5] assert len(items) [1] [2]
The test checks if the length of items is greater than 3. So the operator is > and the number is 3.
Fill all three blanks to create a test that asserts a dictionary has a key 'name' and its value is 'Alice'.
def test_dict(): person = {'name': 'Alice', 'age': 30} assert '[1]' in person and person['[2]'] [3] 'Alice'
The test checks if the key 'name' exists in the dictionary and if its value equals 'Alice'.