Reviewing AI-written code
Generated code tends to look finished, so read it as you would a stranger's pull request. Run it on awkward inputs before you trust it.
What to look for
- State that outlives a call, such as a mutable default argument.
- Float arithmetic on money or other exact quantities.
- Off-by-one errors at boundaries and in paging.
exceptblocks that swallow failures and hide bad data.- Calls to functions that do not exist. Check names against the documentation.
- Tests that assert what the code does, rather than what it should do.
print(int(4.35 * 100)) # 434
print(round(4.35 * 100)) # 435The first line looks reasonable, and its answer is still wrong.
Review by trying
Write down what each function should do for empty input, for one item, and for bad input. Call it with those. Do not accept a fix you cannot explain.
Your task
An assistant wrote these three functions, and each has at least one bug. normalize_emails should trim and lower-case, skip blanks, and drop duplicates within one call. page_of should return a 1-based page and raise ValueError for a page below 1. total_cents should sum decimal price strings exactly and raise ValueError on a bad price. Fix them.
The explanation opens here once every check passes.