Objective
Create a Python program that tests a function with a list of cases using assert.
Instructions
- Define
is_leap(year), which returnsTrueif the year is divisible by 4 and not by 100, or if it is divisible by 400. - Read an integer
nand thennlines with the formatyear expected_result, where the expected result isTrueorFalse. - For each case, inside a
try, checkassert is_leap(year) == expected. If it holds showTest K: OKand ifAssertionErroris raised,Test K: FAIL. K starts at 1. - At the end show
Failures: F.
4
2000 True
1900 False
2024 True
2023 False
Test 1: OK
Test 2: OK
Test 3: OK
Test 4: OK
Failures: 0
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise