0
0
PyTesttesting~10 mins

Basic assert statement in PyTest - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to assert that the sum of 2 and 3 equals 5.

PyTest
def test_sum():
    result = 2 + 3
    assert result [1] 5
Drag options to blanks, or click blank then click option'
A=
B<
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' in the assert statement.
Using '!=' which checks for inequality.
2fill in blank
medium

Complete the code to assert that the length of the list is 4.

PyTest
def test_list_length():
    items = [1, 2, 3, 4]
    assert len(items) [1] 4
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' which check less or greater than, not equality.
Using '!=' which checks for inequality.
3fill in blank
hard

Fix the error in the assert statement to correctly check if the variable is True.

PyTest
def test_is_active():
    is_active = True
    assert is_active [1] True
Drag options to blanks, or click blank then click option'
A==
Bis
C=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' in assert.
Using 'is' which is for identity, not equality.
4fill in blank
hard

Fill both blanks to assert that the variable score is greater than 50.

PyTest
def test_score():
    score = 75
    assert score [1] [2]
Drag options to blanks, or click blank then click option'
A>
B50
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' for greater than check.
Using '<' which checks less than.
5fill in blank
hard

Fill all three blanks to assert that the length of names is less than 5 and the first name is 'Alice'.

PyTest
def test_names():
    names = ['Alice', 'Bob', 'Charlie']
    assert len(names) [1] [2] and names[0] [3] 'Alice'
Drag options to blanks, or click blank then click option'
A<
B5
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for length check.
Using '=' instead of '==' for string comparison.