Premier League Predictor: FastAPI & Redis — Chapter 6, Exercise 2 ================================================================= TASK Write a second version of score_prediction that checks the outcome before the exact score. Run both versions on five cases (including two draws) and report which cases differ and why. SOLUTION def swapped(pred, actual): if sign(*pred) == sign(*actual): # outcome first return 10 return 40 if pred == actual else 0 Cases (predicted, actual): (0-0, 0-0) (1-1, 2-2) (2-1, 1-2) (2-1, 2-1) (3-0, 1-0) Real results: correct order: [40, 10, 0, 40, 10] swapped order: [10, 10, 0, 10, 10] Cases 1 and 4 differ: 0-0 vs 0-0 and 2-1 vs 2-1 are exact matches, and the swapped version scores them 10 instead of 40. An exact score always also has the right outcome, so the outcome check fires first and returns before the exact-match check is ever reached. The other three cases agree because none of them is an exact match, so the order can't matter. Draws are not special: 1-1 vs 2-2 scores 10 in both versions because the outcome (a draw) matches while the scoreline does not. WHY THIS WORKS AS AN ANSWER ---------------------------- It reproduces the bug with real output, identifies precisely which cases are affected (exact matches only), and states the general rule: when one condition implies another, test the more specific one first.