Code Python, Consult AI
Python Fundamentals for the AI Era
Preface

Why This Book Exists
You have been using AI to write code. Maybe it started with a simple request, “build me a web scraper” or “make a script that renames these files”, and it worked. Then you got more ambitious. The code got longer. And at some point, you hit the wall.
The wall is that moment when AI gives you code and you cannot tell whether it is correct. You paste an error back in and get a different error. You ask for a fix and the whole approach changes. You cannot tell which variables matter, what the logic is doing, or why it broke.
This book exists because of the wall.
But the wall is not the only reason to learn Python. AI keeps getting smarter, and the wall keeps moving further out. What does not move is curiosity. The desire to understand what is happening under the hood, not because you have to, but because you want to. Because knowing how code works makes you better at directing AI, better at evaluating its output, and better at building things that actually do what you need.
Whether you hit the wall and need to get past it, or you are simply curious about how the code works, this book gives you that understanding.
There is a deeper reason to learn Python that has nothing to do with writing more code. AI has not earned compiler-grade trust. It is non-deterministic and it fails fluently, which means the checks have to come from outside it. You need enough Python to read the output, test it, and build those checks. Not all of Python. Enough to hold the boundary.
How This Book Works
This is not a traditional Python textbook. You will not read pages of explanations and then try exercises at the end. Instead, you will learn through conversation with AI.
Every chapter follows the same pattern:
The Wall. A specific vibe-coding failure you will recognise. AI produced code that broke or confused you, and you could not diagnose why. This is the concept you are about to learn.
Thinking Session. You open a conversation with your AI assistant and explore the concept. Guided prompts help you ask the right questions, push back on oversimplified answers, and build genuine understanding. No code writing yet. Just thinking.
The Gap. A brief pause where the author connects what you learned to what you are about to build.
Building Session. You open a fresh AI conversation with clear context and direct AI to build something specific. The chatbot project evolves with each chapter, and you understand every line of what AI produces because you explored the concept first.
Quick Reference. A minimal syntax card for future reference.
The two-chat structure used in every chapter comes from the Conversation, Not Delegation framework and is detailed in Converse Python, Partner AI. You do not need to read either to use this book. The method is built into every chapter. Understanding compounds. Each concept makes the next one easier. Vibe coding does not compound. Each session starts from zero.
Who This Book Is For
- People who have used AI to write code and want to understand what it produces
- Professionals who need enough Python to evaluate, modify, and direct AI-generated code
- Anyone curious about how programming works under the hood
- Readers of Think Python, Direct AI ready for deeper language knowledge
If you worked through Think Python, Direct AI, you already used variables, functions, lists, and dictionaries to build projects. This book makes that knowledge systematic. You understand how Python works, not just how to use it.
If you are starting fresh, the book stands on its own. Each chapter’s Thinking Session builds understanding from the ground up through AI conversation.
What This Book Is Not
This is not a computer science textbook. It does not cover algorithms, data structures theory, or computational thinking. That is what Think Python, Direct AI covers.
It is not a professional practices book. Project structure, testing frameworks, deployment, and CI/CD are covered in Ship Python, Orchestrate AI.
It is not a reference manual. It covers the fundamentals you need to read and direct AI-generated code. When you need more, your AI assistant and the official documentation will fill the gaps, and you will be equipped to evaluate what they give you.
The Chatbot Project
Across every chapter, you build a chatbot that grows from a 10-line echo script to a full-featured conversational program. By the end:
- It remembers your name and tracks conversations
- It matches keywords and categorises messages
- It picks responses from configurable dictionaries
- It saves conversation history to files
- It handles errors gracefully
- It has a test suite
- It is structured as a proper Python package with classes
You build this through AI conversation, not by copying code from a textbook. Each Building Session adds one feature, and you understand every line because you explored the underlying concept in the Thinking Session first.
Conventions Used in This Book
AI prompts appear in callout boxes:
What is the difference between a list and a dictionary in Python? When should I use each one?
Code examples appear with syntax highlighting:
name = input("What is your name? ")
print(f"Hello, {name}!")Author guidance appears in tip boxes:
Your AI should explain that lists are ordered by position and dictionaries are ordered by key.
One note on the Building Session listings: from version to version they sometimes trim unrelated earlier features for space. When a listing shows only part of your chatbot, keep the features you have already built; each chapter tells you what to add, never what to remove.
How This Book Was Written
This book was written through human-AI collaboration using the methodology it teaches. The structure, pedagogy, and editorial decisions were made by the author. Claude (Anthropic) assisted with drafting and refining. The process demonstrates the book’s core message: AI is most useful when you understand what you are asking it to do.
Ways to Engage with This Book
- Read it online. The full book is freely available at the companion website, with dark mode, search, and navigation.
- Read it on paper or e-reader. Available as a paperback and ebook through Amazon KDP.
- Converse with it. The online edition includes a chatbot grounded in the book’s content.
- Feed it to your own AI. The
llm.txtfile provides a clean text version of the entire book, ready to paste into ChatGPT, Claude, or any AI tool. - Run the code. Project code is available on GitHub. DeepWiki provides an AI-navigable view of the repository.
- Browse all books. This book is part of a series. See all titles at books.borck.education.
The online version is always the most current.
Source Code & Feedback
All code examples and supplementary materials are available at: https://github.com/michael-borck/code-python-consult-ai
Found an error? Have a suggestion?
- Open an issue: https://github.com/michael-borck/code-python-consult-ai/issues
- Email: michael@borck.me
The Series
This book is part of a series designed to help you master modern software development in the AI era.
The series has a trunk: Conversation, Not Delegation for method and The Human Edge for professional judgement. This book is the Python fundamentals branch.
Two ways in:
| Start with | Continue with | Because |
|---|---|---|
| Conversation, Not Delegation | Build Web, Guide AI, or Converse Python, Partner AI | You want the ideas before (or without) code |
| Think Python, Direct AI | Code Python, Consult AI (this book), then Ship Python, Orchestrate AI | You want to code from your first page |
Converse Python, Partner AI can be read alongside either path; its methodology enhances every one.
- Conversation, Not Delegation: the general methodology for working with AI across any discipline. No code required; the broadest entry point.
- Think Python, Direct AI: computational thinking for absolute beginners. The entry point if you want to code from the start.
- Converse Python, Partner AI: the intentional prompting methodology applied to software development. A companion you can read alongside any Python book.
- Code Python, Consult AI (this book): focused Python fundamentals through AI conversation.
- Ship Python, Orchestrate AI: professional Python development practices and tooling.
- The Absolute Minimum You Must Know: the free, always-current web companion at minimum.borck.education, quick primers on every topic this series covers in depth.
- Build Web, Guide AI: web development with AI as your development partner.
All titles are available at books.borck.education.