Quest 06 · Developers
How to ask an AI for code, and how to check the code you get
I run the smithy. I add up order totals by hand and get them wrong far too often. Could you make a Python function that calculates the total?
Each item in an order has a price in cents and a quantity, and regular customers get a coupon for 0 to 50% off. Anything below one cent is rounded to the nearest cent, with half a cent rounding up.
The developer requests start here. Code is a request too. Everything you learned in request 1 still applies.
Summary
If the code an AI wrote works on one example, are you done? Through the smithy's order ledger, learn what to give when you ask for code, how to check it with tests, and how to point at exactly what to fix.
Pick a function you wrote recently (with secrets removed) and paste it into an AI with the request below. Actually running the tests you get is part of the exercise.
Write tests for the [language] function below. - Include at least one each of normal input, empty input, edge values, and invalid input. - Add one line per test saying what it checks. - If you think there is an input where this function could be wrong, tell me separately. [paste the function here]