Just enough Python
Already comfortable writing Python? Skip to the next lesson. Nothing here is new if you have used the language before.
You do not need to learn programming to finish this course. You need four ideas. This lesson teaches exactly those four and then stops.
Real Python runs in your browser here. Nothing to install, and you cannot break anything.
The four ideas
- Variables give a name to a value.
name = "Ada"means the word Ada is now stored under the namename. - Lists hold several values in order.
["mug", "tea"]is a list of two. - Dictionaries store labelled values.
{"item": "mug", "qty": 2}means the item is a mug and the quantity is two. You will use these constantly, because every message to an AI model is a dictionary. - Loops repeat something until you tell them to stop. That is what makes an agent an agent, and you will write your first one in exercise 10.
Along the way you will also meet functions, which are named blocks of code you
can run again, and if statements, which choose between two paths.
How this lab works
Work down the file, filling in each exercise. Click Run as often as you like.
Exercises 1 to 9 each print a line like PASS:03 when they are right.
Exercise 10 is the real one: a loop that calls chat() and stops at the right
moment.
chat() is provided for you. It talks to a recorded answer, so there is no
account to create and nothing to pay.
The point
Four ideas are enough to build everything in this course. You are not learning Python. You are learning the four bits of it an agent needs.
Break it on purpose
In exercise 10, write while True: chat(messages) with no way out. The page
stops you after a few rounds and tells you the loop never exited. Making that
mistake once here is much better than making it later.