First-time coders
Python Basics
- 30 lessons
- About 60 minutes per lesson
Run your first Python program, then learn input and output, decisions, loops, data collections and functions. Finish by building a program that processes feed requests and deliveries in order.
View the syllabus
What you’ll be able to do
- Read numbers and text, apply a rule and print a result.
- Use decisions, loops and lists to process records, and dictionaries to tally by name.
- Turn a repeated rule into a function and use edge cases to locate a bug.
Course syllabus
Open a module for the lesson breakdown, a worked example and an assignment.
Lessons 1–5 Input, variables and calculations
Read keyboard input, store it in variables and calculate a result.
- Run a first program, change what print says and run it again.
- Store stock and demand in variables and observe what changes after assignment.
- Read a line with input and turn numeric text into an integer with int.
- Compute totals, full bags and remainders with +, -, *, // and %, and check operator order.
- Print numbers in the required format and distinguish a conversion error from a wrong result.
Lessons 6–10 Decisions
Express approvals, waits and restock alerts as clear rules.
- Compare available stock with demand and test the equality case.
- Use if and else to print two possible results and inspect how indentation controls each branch.
- Use elif to write three stock alerts and check the order of thresholds.
- Combine conditions with and, or and not, and trace several truth values.
- Test the branches with inputs just below, at and above the boundary.
Lessons 11–15 Loops and state updates
Repeat a task while carrying the latest stock from one step to the next.
- Repeat a fixed number of times with range and for, checking its endpoints.
- Read several requests in a loop and add up their demand.
- Deduct stock after approved requests and verify the remainder in a trace table.
- Use while to read until a sentinel and inspect what makes the loop stop.
- Test zero requests, exact depletion and processing that continues after an unfilled request.
Lessons 16–20 Strings, lists and dictionaries
Organise records to look up, count and summarise them by name.
- Split an input line into a cow name and an amount.
- Create a list, access a record by index and append new records.
- Traverse a list to compute a total, find a maximum and count matching items.
- Use a dictionary to count each name, handling a first occurrence with get.
- Sum amounts by cow name and check a lookup for a missing name.
Lessons 21–25 Functions and debugging
Extract reusable rules and isolate bugs with small tests.
- Define and call a function, identifying parameters and arguments.
- Return a decision to the caller and let the caller handle the output.
- Reuse one rule for two barns and distinguish local variables from those in the caller.
- Test one function with an ordinary approval, equality and a failure.
- Reproduce a bug with the smallest failing input and compare results before and after the fix.
Lessons 26–30 Project: farm inventory
Combine input, decisions, loops and functions into a complete program.
- Define the input format and distinguish delivery and request events.
- Trace how each event changes the stock and what it prints.
- Read events one line at a time, implement deliveries and then add requests.
- Extract the request rule into a function and retest mixed event sequences.
- Submit runnable code, usage instructions and three input sets with expected output.
A sample exercise
Stock is 7 kg. Process requests for 5, 4 and 2 kg in order.
See the worked example →Common questions
What is the first lesson?
Run a first program, change what print says and run it again. · Input, variables and calculations
How can I check my progress?
Submit a farm inventory program that reports the result of each request or delivery and the final stock. Test exact depletion, an unfilled request and a request after a delivery.