Intermediate · module I1
Python Programming for AI
By the end: Plan a solution as an algorithm, then write, run and debug Python programs that use variables, decisions, loops, collections, functions, searching and sorting algorithms and files, and build a simple chatbot
- Covers
- From planning a solution as an algorithm to writing small AI-style programs in Python
- Contents
- 10 chapters, 34 topics
- Time
- About 6 hours
- Level
- Intermediate
- Your progress
- 0 / 34
Chapter 1 Algorithms and Problem Solving
- 1.18 min Read Activity
From Problem to Algorithm
Inputs, precise steps and outputs, and what makes an algorithm complete and correct
Activity: write the steps to find the largest of three numbers
- 1.210 min Read Activity
Pseudocode and Flowcharts
Writing one algorithm as structured plain language and as a flowchart, using sequence, decision and repetition
Interactive: turn a flowchart into pseudocode
- 1.38 min Read Activity
Tracing an Algorithm by Hand
Dry-running the steps with a trace table to predict the result before any program runs
Activity: trace a loop that totals a list of marks
Chapter 2 Getting Started with Python
- 2.18 min Read Activity
Introduction to Python
What Python is, why AI uses it, and how a program runs
Run a first program in the browser
- 2.210 min Read Activity
Setting Up a Python Environment
Browser playground, Jupyter notebooks, VS Code and Google Colab
Lab: open and run a notebook
- 2.38 min Read Activity
Output, Comments and Program Structure
print(), comments, statements and indentation
Code: print a formatted profile card
- 2.410 min Read Activity
Reading Errors and Debugging
Syntax errors and exceptions, and reading a traceback
Code: fix three broken programs
Chapter 3 Variables and Data Types
- 3.18 min Read Activity
- 3.28 min Read Activity
Data Types
Integers, floats, strings, booleans and None, and type()
Code: identify the type of each value
- 3.38 min Read Activity
- 3.410 min Read Activity
Operators and Expressions
Arithmetic, assignment, comparison and logical operators, and their order
Code: a shopping bill calculator
Chapter 4 Working with Text
- 4.110 min Read Activity
Strings, Indexing and Slicing
Accessing characters and parts of text
Code: extract initials and reverse a word
- 4.210 min Read Activity
String Methods and Formatting
upper, lower, strip, split, replace, join and f-strings
Code: clean and format user input
Chapter 5 Control Flow
Chapter 6 Data Structures
Chapter 7 Functions and Modules
- 7.112 min Read Activity
Defining Functions
Parameters, arguments, return values and default values
Code: a reusable temperature converter
- 7.28 min Read Activity
Scope and Lambda Functions
Where variables live, and short anonymous functions
Code: sort records with a lambda
- 7.310 min Read Activity
Modules and Libraries
import, the standard library, and installing packages with pip
Code: use math, random and datetime
Chapter 8 Algorithms in Python
- 8.18 min Read Activity
Stacks and Queues
Last-in-first-out and first-in-first-out, with a list and collections.deque
Code: an undo button and a print queue
- 8.212 min Read Activity
Linear and Binary Search
Checking items one by one, and halving a sorted list at every step
Code: find a name in a sorted list both ways
- 8.312 min Read Activity
Sorting Algorithms
Selection, bubble and insertion sort written by hand, compared with sorted()
Code: sort scores by hand and check against sorted()
- 8.410 min Read Activity
Recursion
A function that calls itself, the base case and the call stack
Code: factorial and a countdown
- 8.510 min Read Activity
Algorithm Efficiency and Big-O Notation
Counting the steps an algorithm takes as the input grows
Code: count comparisons in linear and binary search
Linear search O(n), binary search O(log n), bubble sort O(n²)
Chapter 9 Files and Exceptions
Chapter 10 Python for AI Projects
- 10.112 min Read Activity
Introduction to Classes and Objects
Bundling data and behaviour, __init__ and self
Code: a Student class
- 10.220 min Read Activity
Project: A Rule-Based Chatbot
Keyword matching, responses and a conversation loop
Project: build a help-desk chatbot
- 10.320 min Read Activity
Project: A Marks Analyser
Reading data, computing statistics and reporting results
Project: analyse a batch of marks from a CSV file
- 10.415 min Read