Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a message when a test passes.
Intro to Computing
if test_result == [1]: print("Test passed!")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using False instead of True
Using 0 or None which mean failure or no result
✗ Incorrect
The test_result should be True to indicate the test passed.
2fill in blank
mediumComplete the code to raise an error if a test fails.
Intro to Computing
if not test_passed: raise [1]("Test failed!")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated error types like TypeError or IndexError
Not raising any error on failure
✗ Incorrect
AssertionError is commonly used to indicate a failed test assertion.
3fill in blank
hardFix the error in the test function to correctly check equality.
Intro to Computing
def test_sum(): result = sum([1, 2, 3]) assert result [1] 6
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != which means not equal
Using > or < which check inequality
✗ Incorrect
The test should assert that the result is equal to 6 using ==.
4fill in blank
hardFill both blanks to create a test that checks if a number is positive.
Intro to Computing
def test_positive(num): assert num [1] 0 and num [2] 0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >
Using == instead of !=
✗ Incorrect
The test checks if num is greater than 0 and not equal to 0.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that filters passing scores.
Intro to Computing
passing_scores = {student: score for student, score in scores.items() if score [1] [2] and student [3] ''} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of >=
Using == instead of !=
Using wrong passing score value
✗ Incorrect
This comprehension keeps students with scores greater or equal to 60 and non-empty names.