Python for AI from Zero: First Program to First LLM Call

You have never written code and you want to build with AI. You write one program from the first lesson to the last: a study assistant for the terminal. It starts as one line that prints a greeting. Then it quizzes you on flashcards from your own notes files, reviews the cards you missed, keeps your best scores, and at the end asks a language model to explain what you got wrong. Each lesson adds one small part that runs, and you finish ready for the courses that start from Python basics.

What this course covers

  1. Write and Run Your First Program: Write a one-line Python program in an editor, run it from the terminal, and use the error message to find a mistyped line.
  2. Values and Variables: Store numbers and text in variables, compute with them, and predict what a line that prints them will show.
  3. Read an Answer and Compare It: Read a line the user types, tidy it, compare it with an expected value, and predict whether the comparison gives True or False.
  4. Make Decisions with if, elif and else: Write code that picks one of several branches from conditions, and predict which branch runs for a given input.
  5. Try Again with a while Loop: Repeat a block of code with a while loop until a condition changes, and predict how many times it runs.
  6. Many Cards: Lists and for Loops: Keep several values in a list, reach one by its index, and use a for loop to run the same code for every item.
  7. Collect the Cards You Missed: Build a list while a program runs by collecting the items that pass a test, and act on whether the list ended up empty.
  8. Give Each Job a Name with Functions: Move repeated code into a function with parameters and a return value, call it with different arguments, and predict what a call gives back.
  9. Dictionaries: Records with Named Parts: Keep related values together in a dictionary, read and change them by key, and loop over a list of dictionaries.
  10. Read Cards from a Notes File: Import a standard library module, read a text file through a path, and turn its lines into a list the program can loop over.
  11. Choose a Subject and Handle Errors: Read a traceback to find what failed and where, and handle an expected error with try and except so the program explains the problem.
  12. Keep Your Best Scores in a JSON File: Save a dictionary to a JSON file and load it back on the next run, including the first run when no file exists.
  13. Split the Program into Modules: Split a program into modules, import functions from one file into another, and predict what runs when a module is imported.
  14. Install pytest and Write a First Test: Add a package to a project, write a test function that checks one function with assert, run the tests and read a failure report.
  15. A Class of Your Own: the Flashcard: Define a class with __init__ and a method, create objects from it and call the method on them, and explain what self refers to in a call.
  16. Settings and Secrets in a .env File: Read settings from environment variables loaded from a .env file, explain why a secret never goes into the code, and report a missing setting with a clear message.
  17. Call a Web API by Hand: Send a request to a web API from Python, check the status code, and pick a value out of the JSON that comes back.
  18. Explain Missed Cards with a Language Model: Call a language model from a Python program with the openai package, build the prompt from the data of the program, and keep the program working when the call fails.