📊 We use cookies & analytics to improve your experience. Learn more
Latest

AI Tools Mastery for Freshers Module 4 · Lesson 13 of 15

0% Exit to course

Module 4 · Do the work — and keep your judgement Lesson 13 of 15

Code: draft it, read it, debug it

Learning objective

Use AI as a fast first draft and a patient explainer, never as code you paste without reading. Ask it to explain its own code line by line, to find a bug from the error message, and to show the smallest example first. If you cannot explain the code, you cannot defend it in an interview or maintain it in the job.

The concept

Use AI as a fast first draft and a patient explainer, never as code you paste without reading. Ask it to explain its own code line by line, to find a bug from the error message, and to show the smallest example first. If you cannot explain the code, you cannot defend it in an interview, and you cannot fix it when the data changes.

The mistake is shipping code you cannot read. Break it on purpose — delete a quote, pass a file that does not exist — and read the error before you ask for help. Understanding the error message is a real skill, and this is the cheapest place to build it.

Prompt
Write a Python function that reads a CSV file and prints the average
of the "marks" column.
Then explain every line as if teaching a beginner.
Finally, tell me what happens if one cell in that column is blank,
and show the smallest change that handles it.
Python
import csv

def average_marks(path):
    total, count = 0, 0
    with open(path, newline="") as f:
        for row in csv.DictReader(f):
            value = row.get("marks", "").strip()
            if value:                       # skip blank cells
                total += float(value)
                count += 1
    return total / count if count else 0

print(average_marks("students.csv"))

Worked example

Write a Python function that reads a CSV and prints the average of the marks column. Then explain every line as if teaching a beginner, and tell me what happens if one cell is blank.

Your practice task

Generate one small script, run it, break it on purpose, and fix it using only the error message.

Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.

Key takeaway

Use AI as a fast first draft and a patient explainer, never as code you paste without reading.

Create free account or sign in

Almost there

15 lessons left of 15

Finish every lesson to unlock the certificate. Each one ends in a practice task — do them and the final project brief writes itself.