Coding with AI: Python for Absolute Beginners
You don’t need to become a programmer to benefit from code. Even ten lines of Python can automate a boring task, perform a complex calculation, or build a tiny tool. And you don’t need to install anything—the AI can simulate the output so you see exactly what the code does, or you can run it live on any free Python website. All you need are four magic prompts.
⚡ Jump to a Section
Hello, World!
Build a Calculator
Rename Files Safely
Read Code Line‑by‑Line
Debug Errors
Try a Mini‑Project
🪄 The Four Magic Code Prompts
Every coding task with an AI boils down to four simple commands. You already know the CTFC framework; now just apply it to code.
Explain this code line by line as if I’m a complete beginner.
Debug this code. The error message is: [paste error].
Modify this code to [add feature or change behaviour].
With these four, you can generate, understand, fix, and adapt code. You’re the director; the AI is the developer.
- Case matters:
Printis notprint. Keep it lowercase. - Indentation is mandatory: code inside a loop or function must be indented consistently (4 spaces is standard).
👋 Warm‑Up: Hello, World! Five Times
Prove the concept instantly. Prompt: “Write Python code that prints ‘Hello, world!’ 5 times, then explain each line in plain English.”
print(“Hello, world!”)
Hello, world!
Hello, world!
Hello, world!
Hello, world!
The AI will explain that for i in range(5): creates a loop that runs five times. You’ve just read and understood a loop.
💰 Task 1: Build a Compound Interest Calculator
Automate a real financial calculation. The formula is A = P × (1 + r/n)^(n×t).
AI‑generated code:
rate = 0.05 # 5% annual interest rate
periods_per_year = 12 # monthly compounding
years = 10
# Formula: A = P * (1 + r/n)^(n*t)
amount = principal * (1 + rate / periods_per_year) ** (periods_per_year * years)
print(f”After {years} years, you’ll have £{amount:.2f}”)
Now practise the Modify prompt: “Modify the calculator to compare monthly vs annual compounding.” The AI updates the code, and you see the difference instantly.
📁 Task 2: Rename a Bunch of Files Safely
Real‑world automation that touches your computer. The golden rule: always do a dry run first.
AI‑generated safe code (abbreviated):
folder = “/path/to/your/folder” # CHANGE THIS
for filename in os.listdir(folder):
if filename.startswith(“IMG_”):
new_name = filename.replace(“IMG_”, “Holiday_”, 1)
print(f”Would rename: {filename} -> {new_name}”)
# After verifying, uncomment the confirmation block to actually rename
This first run shows you every planned change. After checking, you uncomment the lines that ask "Confirm rename? (yes/no):" and run again. Safe and transparent.
📖 Read Code Like a Pro: The Line‑by‑Line Technique
Whenever you see code you don’t understand, paste it and say: “Explain this code line by line, defining any jargon.”
Example: For if filename.startswith("IMG_"): the AI will say: “This line checks if the filename begins with the letters ‘IMG_’. The startswith() method returns True or False. It’s a string method – a built‑in function that text objects understand.” You’ll learn what a “method”, a “string”, and a “condition” are in one sentence.
🐞 Debugging: Turn Errors into Learning
Errors aren’t failures—they’re clues. Here’s a classic beginner mistake:
print(“Next year you will be ” + (age + 1))
Error: TypeError: can only concatenate str (not "int") to str
Prompt: “Debug this code. Explain the error and fix it.”
AI response: “input() returns a string (text). You tried to add 1, which is an integer, to a string. Convert age to an integer first with int(input(...)). Then convert the result back to a string when printing.” Fixed code:
print(“Next year you will be ” + str(age + 1))
You’ve just learned about data types, type conversion, and error messages—all by breaking something and fixing it with the AI.
🧪 Try It Now: Pick a Mini‑Project
Use the four magic prompts to complete one of these. Don’t worry about getting it perfect—just prompt the AI, read the code, and run it (simulated or real).
Mini‑Project 2 – Tip Calculator: Calculate a 15% tip, split among N people, and print the per‑person amount.
Mini‑Project 3 – Word Counter: Count the number of words in a sentence the user inputs. Hint: use
.split().
After completing one, ask the AI to explain the code line by line, then modify it (“change the tip to 18%” or “also count letters”). This loop—write, explain, modify—is exactly how you grow as a coder.
You’ve written real code. Now, when should you use DeepSeek vs ChatGPT vs Claude for different tasks?