Free AI code generator
Write code, fix bugs and explain how it works.
def monthly_total(orders):
totals = {}
for order in orders:
month = order["date"][:7]
totals[month] = (
totals.get(month, 0)
+ order["amount"]
)
return totals
orders = [{"date": "2026-09-01", "amount": 20},
{"date": "2026-09-12", "amount": 35}]
assert monthly_total(orders) == {"2026-09": 55}
What you get
Code with an explanation and steps to run or test it.
For a better result
Include sample inputs and expected outputs. Review dependencies, security and edge cases before using generated code in production.
From brief to result
- What to provide
- Name the language, inputs, expected output and constraints.
- Edit and use
- Get editable source code with steps to run it.
- What to check
- Ask for tests with example inputs and edge cases. Review dependencies and credentials before running generated code.
Sign in to generate in your workspace. Your free starter allowance is shared across tools; the number of results depends on the task and settings. See plans and usage.
Example briefs
Python script
Write a Python script that reads orders.csv, groups sales by month, and saves monthly_totals.csv. Columns: date, order_id, amount. Handle invalid dates and missing amounts explicitly.
React component
Build an accessible React and TypeScript search component with a labeled input, debounced filtering, loading and empty states. Include a small usage example.
Debug code
Help me debug this Python function. It should return an empty list for n=0 and the first n Fibonacci numbers otherwise: def fib(n): result = [0, 1] for i in range(2, n): result.append(result[-1] + result[-2]) return result