Basic checks on the arguments to the rod-cutting algorithms * `n`: int, the length of the rod * `prices`: list, the price list for each piece of rod. Throws ``ValueError``: if `n` is negative or there are fewer items in the price list than the length of the rod
(n: int, prices: list)
| 175 | |
| 176 | |
| 177 | def _enforce_args(n: int, prices: list): |
| 178 | """ |
| 179 | Basic checks on the arguments to the rod-cutting algorithms |
| 180 | |
| 181 | * `n`: int, the length of the rod |
| 182 | * `prices`: list, the price list for each piece of rod. |
| 183 | |
| 184 | Throws ``ValueError``: |
| 185 | if `n` is negative or there are fewer items in the price list than the length of |
| 186 | the rod |
| 187 | """ |
| 188 | if n < 0: |
| 189 | msg = f"n must be greater than or equal to 0. Got n = {n}" |
| 190 | raise ValueError(msg) |
| 191 | |
| 192 | if n > len(prices): |
| 193 | msg = ( |
| 194 | "Each integral piece of rod must have a corresponding price. " |
| 195 | f"Got n = {n} but length of prices = {len(prices)}" |
| 196 | ) |
| 197 | raise ValueError(msg) |
| 198 | |
| 199 | |
| 200 | def main(): |
no outgoing calls
no test coverage detected