Fix the discount screen for an order endpoint
Your task
An AI wrote a DRF endpoint that applies a percent discount to an order. Its serializer checked only that the percent was a number, so finance found orders with 300 percent discounts and negative totals. Your team now screens every discount request with business rules before it touches an order.
An assistant wrote screen_discount_requests(percents, max_percent). It is in the editor. It has a bug. Find it and fix it.
Input and output:
percents: the requested discounts, as numbers that may have decimals.max_percent: the most this user's role may grant, as a number. A bad config can make it 0 or negative.- Return one verdict per request, in the same order.
Rules the tests check:
- A request's verdict is the first of these that applies:
"rejected_negative"when the percent is below 0."rejected_above_100"when the percent is above 100."rejected_above_policy"when the percent is abovemax_percent."accepted"otherwise.
- Compare the numbers exactly, with no rounding.
Examples
screen_discount_requests(percents: list[float], max_percent: float) -> list[str]Example 1
Input
screen_discount_requests([10, 300, -50], 25)Output
["accepted", "rejected_above_100", "rejected_negative"]Example 2
Input
screen_discount_requests([25, 25.5], 25)Output
["accepted", "rejected_above_policy"]Example 3
Input
screen_discount_requests([], 50)Output
[]