0
0
PyTesttesting~10 mins

Comparing values (equality, inequality) 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 check if the variable result equals 10 using pytest.

PyTest
def test_result():
    result = 10
    assert result [1] 10
Drag options to blanks, or click blank then click option'
A==
B<
C>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes the test to fail.
Using '>' or '<' checks for greater or less, not equality.
2fill in blank
medium

Complete the code to assert that value is not equal to 5.

PyTest
def test_value_not_five():
    value = 3
    assert value [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 '!=' will fail if value is not 5.
Using '>=' or '<=' checks range, not inequality.
3fill in blank
hard

Fix the error in the assertion to check if score is greater than or equal to 50.

PyTest
def test_score():
    score = 75
    assert score [1] 50
Drag options to blanks, or click blank then click option'
A==
B<
C!=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' only checks equality, not greater values.
Using '<' checks if less, which is the opposite of what we want.
4fill in blank
hard

Fill both blanks to assert that temperature is less than 100 and not equal to 0.

PyTest
def test_temperature():
    temperature = 75
    assert temperature [1] 100 and temperature [2] 0
Drag options to blanks, or click blank then click option'
A<
B!=
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' for the first blank reverses the logic.
Using '==' instead of '!=' for the second blank causes wrong assertion.
5fill in blank
hard

Fill all three blanks to create a test that asserts age is greater than 18, less than 65, and not equal to 30.

PyTest
def test_age():
    age = 40
    assert age [1] 18 and age [2] 65 and age [3] 30
Drag options to blanks, or click blank then click option'
A>
B<
C!=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up '<' and '>' operators.
Using '==' instead of '!=' for the last condition.