Coding and automationIntermediateFree

Explain a piece of code

Walks through code step by step: what it does and what could go wrong.

The prompt

Explain this [language] code to me. I’m [your experience, such as a beginner who knows the basics]. It’s from [where it comes from, such as a script at work or a tutorial]. Tell me: what it does overall, in two sentences; what each part does, step by step; anything risky or likely to break, such as missing error handling or a password written into the code; and the first improvement you’d make. Keep it plain and patient, and don’t rewrite the whole thing. If you’d need to see more of the code to be sure, say so. The code: [paste the code, with any passwords, keys or private data removed]

Tips for a better answer

  • Never paste passwords, API keys or customer data. Swap them for placeholders such as API_KEY.
  • Only run code once you understand what it does, and try it on a copy of your data first.

An example, filled in

Explain this Python code to me. I’m someone who can read a little Python. It’s from a script a former colleague left on our shared drive. Tell me: what it does overall, in two sentences; what each part does, step by step; anything risky or likely to break, such as missing error handling or a password written into the code; and the first improvement you’d make. Keep it plain and patient, and don’t rewrite the whole thing. If you’d need to see more of the code to be sure, say so. The code: import csv with open('orders.csv') as f: rows = list(csv.DictReader(f)) total = sum(float(r.get('amount', 0)) for r in rows if r.get('status') == 'paid') print(total)

Before you paste it in. Leave out names, contact details, passwords and anything confidential. At work, use the AI tools your employer has approved, and check what comes back before you rely on it. Using AI at work safely

Spotted a problem with this prompt? Tell us and an editor will check it.

More prompts for coding and automation

All the prompts for coding and automation, on one page

Get AI explained at your level, every weekday

The five stories that matter, in plain English, with a prompt of the day. Free.