← All courses

Course 0.5 · AI-Powered Programming · about 14 min

Code is instructions, AI is your helper

By the end of this course you can read short Python programs, predict what they print, and use an AI assistant to explain and fix code without trusting it blindly.

A program is a list of instructions that the computer follows one line at a time, from top to bottom. Almost every AI project you'll see in this school is written in Python, because it reads almost like English and has great AI libraries.

Today an AI assistant (like ChatGPT, Claude or Gemini) can write a lot of code for you. That makes you faster, but only if you can read what it wrote and check that it works. Think of the AI as a quick pair programmer who is sometimes confidently wrong. You stay the one in charge.

Nothing to install today. Everything runs right here on this page. Later you can try the same code for free in a notebook such as Google Colab.

Try itWorking with an AI assistant: good habit or risky?

CheckThe AI wrote code that looks right. What should you do next?

Step 2

Variables: names for values

A variable is a name that points to a value. You create one with =, which means "store this", not "is equal to":

print(...) shows values on the screen. Give it several values separated by commas and it prints them with spaces in between.

name = "Ada"
age = 36
age = age + 1
print(name, "is", age)

PredictWhat does this program print?

Try itStep through it

Run the program one line at a time and watch the variables change.

name = "Ada"age = 36age = age + 1print(name, "is", age)
Variables
Output

      

CheckWhat does age = age + 1 do?

Step 3

Lists and loops: repeat without retyping

A list keeps several values in order: scores = [7, 9, 4]. A for loop runs the indented lines once for every item in the list, so you never have to copy the same line three times.

The indented lines (four spaces) belong to the loop. When the list runs out, Python continues with the first line that isn't indented. len(scores) gives the number of items, and / divides.

This tiny pattern, going through data and adding things up, is at the heart of how machine learning measures errors and accuracy.

scores = [7, 9, 4]
total = 0
for s in scores:
    total = total + s
print(total / len(scores))

PredictWhat does this program print?

Try itStep through the loop

Watch s take each value from the list while total grows.

scores = [7, 9, 4]total = 0for s in scores:    total = total + sprint(total / len(scores))
Variables
Output

      

CheckHow does Python know which lines belong to the loop?

Step 4

Decisions with if

Programs make choices with if. Python checks each condition from the top and runs only the first branch that is true. elif means "else, if", and else catches everything left over.

Comparisons give True or False: > greater than, < less than, == equal to. A spam filter, a self-driving car's brake decision or a chatbot's safety check all end in an if-statement somewhere.

Try itMove the temperature

Watch which line runs. Only one branch ever runs.

18
temp = 18if temp > 25:    print("Beach")elif temp > 15:    print("Walk")else:    print("Read a book")
Output

PredictIf temp is exactly 25, what is printed?

CheckSeveral conditions in an if / elif chain are true. What runs?

Step 5

Fix bugs with AI, the smart way

Everyone's code breaks. Here someone tried to print the average with a label, and Python stopped with an error:

print("Average: " + total / len(scores))
TypeError: can only concatenate str (not "float") to str

The error says: you can't glue text (str) and a decimal number (float) together with +. When you ask an AI for help, give it the code, the full error and what you wanted. Compare these two prompts:

Weak:  my code doesn't work, fix it
Strong: This Python line should print "Average: 6.67".
print("Average: " + total / len(scores))
It fails with: TypeError: can only concatenate str (not "float") to str
Explain the error in simple words, then show the smallest fix.

A typical answer suggests an f-string, which puts values inside text: print(f"Average: {total / len(scores):.2f}"). The :.2f rounds to two decimals. Then you run it and check that it really prints Average: 6.67.

Try itPut the debugging loop in order

Tap the first step, then the next.

CheckWhich prompt gets the most useful help with a bug?

Step 6 · Recap

What you learned

Quick reviewThree questions from memory. No scrolling back.

Next up: Course 1, AI Fundamentals. Mark this course complete below when you're ready.