Blog › Python
Python for total beginners: your first ten lines
Python is the language most people learn first, and the one most AI tools are written in. It reads almost like English. Here are ten lines that use the handful of ideas you will meet in every program.
name = "Bitsy"
print("Hello, I am", name)
snacks = 3
print("I have", snacks, "snacks")
if snacks > 2:
print("That is plenty!")
else:
print("Time to shop.")
for n in range(1, 4):
print("Crunch", n)
print: make your program talk
print() shows whatever is inside the brackets. Words go in quotes; numbers and names of variables do not. Commas put a space between the pieces.
Variables: give things a name
name = "Bitsy" stores the text Bitsy under the name name. The equals sign means "store", not "is equal to". Later lines can use the name instead of the value, and if you change the value in one place, every line that uses it changes too.
if and else: make a choice
if snacks > 2: asks a yes-or-no question. The lines pushed in by four spaces underneath only run when the answer is yes. else: is what happens otherwise. Those spaces at the start of the line matter in Python: they tell it which lines belong to the if.
for loops: do it again
for n in range(1, 4): runs the lines under it once for each number from 1 up to (but not including) 4. So it prints Crunch 1, Crunch 2 and Crunch 3. Loops are how a program does a thousand things without a thousand lines.
input: ask the person
One more you will use all the time: answer = input("What is your name? ") waits for the person to type something and stores it. With print, variables, if, loops and input, you can already make a small game.
Three mistakes everyone makes
- A missing colon. Lines that start with if, else, for, while and def end with
:. - Spaces that do not line up. Everything inside an if or a loop needs the same four spaces.
- Capitals.
Printandprintare different words to Python. So areNameandname.
When Questzo's checks fail, they say which instruction did not pass, and the Ask Pip button explains the error in plain words, including the line it happened on.
Try it
Quest 1, Wake Up starts with a single print(). It runs in your browser, needs no sign-up, and takes about five minutes.
Learn it by building it
Questzo teaches Python by building an AI agent, one pixel quest at a time. The first two chapters are free, with no sign-up.
Start the first quest