Ravindra BagaleCourses & study guides Track your progress
AI CODING ASSISTANTS · CHAPTER 1

What Is an AI Coding Assistant

An AI coding assistant is a helper inside your code editor. You tell it what you want in plain words. It writes or fixes the code. You check it and run it.

In short: it is an AI that lives in your editor, turns your words into code, and speeds up your work — but you stay in charge of reviewing and testing.

Why it matters

WHY

Writing code by hand is slow. An assistant does the boring parts fast: boilerplate, small functions, tests, fixing errors. You spend more time on the real problem. It is also a great teacher — it can explain code in simple words.

What the words mean

WHAT
  • AI coding assistant: a tool in your editor that writes code from your request.
  • LLM (large language model): the "brain" that was trained on lots of code and text.
  • Prompt: the request you type (a sentence, or a code comment).
  • Context: the files and text the assistant can see when it answers.
  • Suggestion: the code it offers; you accept or reject it.

How it works, top to bottom

1 · You type a request plain words or a comment 2 · Assistant reads context your open files + prompt 3 · AI model writes code suggestion, chat, or edits 4 · You review it read, understand, change 5 · You run and test keep only what works

The three modes

HOW

Almost every assistant works in three modes. You will switch between them all day.

  1. Inline (autocomplete): as you type, it shows faint "ghost" code. Press Tab to accept. Best for finishing a line or a small function.
  2. Chat: a side panel where you ask questions like "write a function that reads a CSV" or "why is this error happening?". Best for bigger blocks and learning.
  3. Agent: you give a goal; it edits several files and can run commands — asking your approval. Best for multi-step tasks. More power means more care.
COMPARISON CARDAI Coding

Chat vs Inline vs Agent

Inline: grey ghost text as you type; press Tab to accept.
Chat: you ask in a side panel; it explains or writes blocks.
Agent: it edits many files and runs commands, with your approval.
Ravindra Bagale · ravindrabagale.com/ai-coding

How to prompt for code (simple rules)

  1. Say the goal + the inputs + the output. "Write a Python function that takes a list of numbers and returns the average."
  2. Name the language and tools. "Use pandas." "No external libraries."
  3. Give an example of input and expected output when you can.
  4. Ask for small pieces, then build up. Short requests give better code.

Always review and test AI code

  1. Read it line by line. If you do not understand a line, ask the assistant to explain it.
  2. Run it on a small example and check the result.
  3. Write a test (you can ask the AI for one) and run it.
  4. Watch for made-up things — AI can invent function names or libraries that do not exist. Check the docs.
Rule: AI code can look right but be wrong. Never ship code you have not read and run.

Safety basics

  • Never paste secrets (passwords, API keys, real customer data) into a cloud assistant.
  • Check licences if it produces a large chunk that looks copied.
  • For private data, use a local model (Ollama) so nothing leaves your machine — see Keep data at yourself.

Practice: your first explain, fix and verify loop with any AI coding assistant

Hello friends. The chapter above explained what an AI coding assistant is and why you must review and test its code. Now you will practise the full loop once. The practice is a fictional stall called Mango Grove Juice Corner, which sells three sizes of mango juice. First you ask the assistant to explain the code without changing it, then you ask it to fix the bug, and then you read the change and run the tests yourself. The starter file fails 4 tests and passes 3, and a correct fix passes all 7.

Ravindra Bagale's Tip

Ask the assistant to explain the code before you ask it to change anything. When you understand the bug yourself, it is much easier to judge whether the fix is right.

Practice label: Mango Grove Juice Corner and its juice prices are fictional teaching data. It is not a real business, and no real customer data is used. Passing these tests proves only the listed cases.
Environment (tested): on 16 November 2026 the starter and fixed files below were run on this course's Linux build machine with Python 3.13.5 and pytest 9.1.1. Starter: 4 failed, 3 passed. Fixed file: 7 passed. The AI tool itself runs on your own computer, so its words will differ from any example here.
Checked against official docs: every menu name, command and setting in this practice was checked on 16 November 2026 against this course's setup chapters for GitHub Copilot, Continue, Claude Code, Codex and Cursor, which link to each tool's official docs. This practice uses only the chat panel and a normal terminal, so it works with any of them. These tools update often. If a menu name looks different on your screen, search for the same words in the official docs or the Command Palette, and do not guess.

Your task: open the practice folder in your editor, ask your AI coding assistant to explain juice_price, and then ask it to fix the function so that sizes work with capital letters and extra spaces, and an unknown size raises ValueError with a message that contains size.

Setup (practice folder mango-juice)

HOW
  1. Create the practice folder with the name shown below, and save the two files from this section inside it.
  2. Create a virtual environment: on macOS or Linux run python3 -m venv .venv. On Windows run py -3 -m venv .venv.
  3. Activate it: on macOS or Linux run source .venv/bin/activate. In Windows Command Prompt run .venv\Scripts\activate.bat, and in Windows PowerShell run .venv\Scripts\Activate.ps1.
  4. Install pytest inside the virtual environment: python -m pip install pytest.

Starter juice_price.py ("Large" and " small " are not found, and an unknown size quietly returns None instead of an error):

juice_price.py
PRICES = {"small": 30, "medium": 45, "large": 60}


def juice_price(size):
    """Fictional Mango Grove Juice Corner: price in rupees for one glass of mango juice."""
    return PRICES.get(size)

Simple tests test_juice_price.py:

test_juice_price.py
import pytest

from juice_price import juice_price


def test_small_glass():
    assert juice_price("small") == 30


def test_medium_glass():
    assert juice_price("medium") == 45


def test_large_glass():
    assert juice_price("large") == 60


def test_capital_letters_are_accepted():
    assert juice_price("Large") == 60


def test_extra_spaces_are_ignored():
    assert juice_price("  small ") == 30


def test_unknown_size_is_rejected():
    with pytest.raises(ValueError, match="size"):
        juice_price("jumbo")


def test_empty_size_is_rejected():
    with pytest.raises(ValueError, match="size"):
        juice_price("")

Before you ask the AI, run python -m pytest -q in the folder. You should see 4 failed, 3 passed. That proves Python and pytest work before the AI tool is involved.

The exact prompt to try (copy it as it is):

explain-then-fix-prompts.txt
Prompt 1 (explain only): Explain in simple words what juice_price does and why some tests in test_juice_price.py fail. Do not change any file yet.

Prompt 2 (fix): Now fix juice_price in juice_price.py for the fictional Mango Grove Juice Corner. Ignore capital letters and extra spaces in size, so "  Large " costs 60. Raise ValueError with a message that contains size when the size is unknown or empty. Do not change test_juice_price.py.

HOW to run the explain, fix and verify loop

HOW
  1. Open the folder: open mango-juice in your editor and open juice_price.py. Any assistant from this course works, such as GitHub Copilot, Continue, Claude Code, Codex or Cursor.
  2. Open the chat panel: open your assistant's chat and add juice_price.py and test_juice_price.py to the chat if your tool asks for files.
  3. Ask for an explanation first: send Prompt 1 and read the answer. A good answer says that the dictionary lookup needs an exact match and that get returns None for a missing size.
  4. Ask for the fix: send Prompt 2. If your assistant shows a diff, read it before you accept it. If it only shows code in the chat, copy it into the file yourself.
  5. Read the change line by line: make sure that only juice_price.py changed and that the prices are still 30, 45 and 60. If you do not understand a line, ask the assistant to explain that line.
  6. Confirm yourself: in the terminal, with your virtual environment active, run python -m pytest -q. Expect 7 passed.

What a correct result looks like: The explanation says that the starter needs an exact size such as large and returns None for any size it does not know. The fix cleans the size with strip() and lower() and raises ValueError with size in the message when the cleaned size is not in the price list. The exact words and code style change from tool to tool and from run to run, which is fine. The result is correct only when pytest shows 7 passed.

Real pytest output after the fixed file:

pytest-after.txt
.......                                                                  [100%]
7 passed in 0.01s
Optional completed juice_price.py (try it yourself first)

Your assistant may use casefold() instead of lower(), or a different error message. Any version is fine if all 7 tests pass and the test file is unchanged.

juice_price.py
PRICES = {"small": 30, "medium": 45, "large": 60}


def juice_price(size):
    """Fictional Mango Grove Juice Corner: price in rupees for one glass of mango juice."""
    key = size.strip().lower()
    if key not in PRICES:
        raise ValueError(f"unknown size: {size!r}")
    return PRICES[key]

Troubleshooting: common problems in your first AI fix

HOW
  1. Problem: the assistant changed the code when you only asked for an explanation. Fix: undo the change with your editor's undo, or reject the edit. In tools with modes, choose the ask or chat mode for questions, and say clearly that no file should change yet.
  2. Problem: the fix returns 0 or None for an unknown size instead of raising an error. Fix: that hides the mistake from the shop. Tell the assistant that the test expects ValueError with size in the message, and ask again.
  3. Problem: the assistant changed test_juice_price.py so that the tests pass. Fix: reject that change. The tests describe the correct prices, so only juice_price.py should change.
  4. Problem: the assistant says that the tests pass, but you have not run them. Fix: always run python -m pytest -q yourself. An assistant can make mistakes, and only a real test run proves the result.
  5. Problem: the assistant imports a package that you do not have. Fix: this small fix needs only plain Python. Ask the assistant to solve it without any external library, and check the official docs before you install anything it suggests.
  6. Problem: pytest says command not found or No module named pytest. Fix: activate your virtual environment, install pytest with python -m pip install pytest, and run the tests with python -m pytest -q.

Practice cards: English and spoken Marathi

Each card below explains one idea on its own, so you can save or revise a single card without reading the whole chapter.

PRACTICE CARDAI Coding

Explain first, then fix

Ask the assistant to explain the code and the failing tests before it changes anything.
When you understand the bug yourself, you can judge whether the fix is right.
Ravindra Bagale · ravindrabagale.com/ai-coding
PRACTICE CARDAI Coding

Only your test run counts

An assistant can say that the tests pass even when they do not.
Run python -m pytest -q yourself, and keep the code only when every test passes.
Ravindra Bagale · ravindrabagale.com/ai-coding
सराव कार्डमराठी

आधी समजून घ्या, मग fix करा

काहीही बदलण्याआधी assistant ला code आणि fail होणारे tests समजावून सांगायला सांगा.
Bug तुम्हाला स्वतः समजला की fix बरोबर आहे की नाही ते तुम्ही ठरवू शकता.
Ravindra Bagale · ravindrabagale.com/ai-coding
सराव कार्डमराठी

फक्त तुमचा test run ग्राह्य धरा

Tests pass झाले नसले तरी assistant ते pass झाले असं सांगू शकतो.
python -m pytest -q स्वतः चालवा, आणि सगळे tests pass झाले तरच code ठेवा.
Ravindra Bagale · ravindrabagale.com/ai-coding

Quick quiz

1. What are the three main modes?

Inline (autocomplete), chat, and agent.

2. What must you always do with AI code?

Read it, run it, and test it before trusting it.

3. What is a "prompt"?

The request you type — a sentence or a code comment.

4. What should you never paste into a cloud assistant?

Secrets: passwords, API keys, or real customer data.

Save tokens and money

SMART AI USE

Use inline mode for small stuff (it is cheap and fast). Save chat/agent for real problems. Ask for "only the code" to get shorter answers. See more AI Coding guides.

Save these cards

INTERVIEW CARDAI Coding

What is an AI coding assistant?

Answer: a tool inside your editor that suggests, writes or edits code from your prompt, using a large language model.
Key line: it is a helper, not a replacement — you still review and test.
Ravindra Bagale · ravindrabagale.com/ai-coding
REVISION CARDAI Coding

AI assistant in 3 ideas

1 Input: your prompt + the code it can see.
2 Output: suggestions you accept or reject.
3 Rule: always read and test before you trust it.
Ravindra Bagale · ravindrabagale.com/ai-coding