Your eval ends with a report, and a report only helps when someone reads it. On a busy day nobody does, and a prompt change that breaks the assistant goes out anyway. So a team turns its eval into a gate: a script that runs on every change and answers yes or no by itself.
A gate needs a bar. Yours is THRESHOLD = 90: at least 90% of the cases must pass. The gate counts whole cases, so it rounds the number up with math.ceil. With 20 cases the bar asks for 18. With 27 cases, 90% is 24.3, and the bar asks for 25.
math.ceil(18.0) # 18 math.ceil(24.3) # 25
The gate must also speak to tools. Every program hands a number to whoever started it when it ends: its exit code. 0 means all went well, any other number means it failed. CI, the service that runs a project's checks on every change, reads only that number.
python check_links.py → exit code 0 → the change may go on python check_links.py → exit code 1 → CI blocks the change
When you are done, the end of your program's output must read:
FAIL: 18/27 < 25/27 The check read the program's exit code: 1 The check called gate with other scores: gate(8, 10) printed "FAIL: 8/10 < 9/10" and returned False gate(9, 10) printed "PASS: 9/10" and returned True gate(43, 48) printed "FAIL: 43/48 < 44/48" and returned False gate(44, 48) printed "PASS: 44/48" and returned True
Your task: the eval from the last lessons is already in the editor, with THRESHOLD = 90 and the imports of math and sys. At the end of the program, write a function gate(passed, total). Below the bar it prints a line like FAIL: 8/10 < 9/10 and returns False. Otherwise it prints a line like PASS: 9/10 and returns True. Then give it this run's score, and end the program with exit code 1 when it says no.
Assignment
Follow the Coding Tutorial to write the function gate, give it this run's score and exit with code 1 when the score is below the bar.
Hint
The gate compares whole cases, not the rounded percent: 43 of 48 is 89.58%, which the report shows as 90%, and it is still below the bar. Printing FAIL doesn't change the exit code. Only sys.exit(1) does.
Free plan: 30 tutor messages. PRO is unlimited.
