CodeCourse
Learn Python by actually writing Python. Six levels. Real code. Instant feedback. No installs and no account required.
Python engine loads the first time you press Run — give it a few seconds.
Foundations
Every program starts with two things: telling the computer something (with print),
and remembering something (with a variable). Python reads top to bottom, one line at a time,
exactly like a recipe.
A variable is just a labeled box. name = "Ava" creates a box called
name and puts the text "Ava" inside it. Text goes in quotes — that's
called a string. Numbers don't need quotes.
Read this example
name = "Ava"
age = 12
print("Hello,", name)
print(name, "is", age, "years old")
Now try it yourself
Your turn
- Add a second variable called
favorite_languageand print a sentence using it. - Change
ageto your own age and print a sentence with bothnameandage.
Control Flow
Real programs make decisions. An if statement checks whether something is true,
and only runs its block when it is. elif checks another condition, and
else catches everything left over.
Comparisons like >=, ==, and != return
True or False — that's what if is actually reading.
Read this example
age = 14
if age >= 13:
print("You're a teenager!")
else:
print("Not a teenager yet.")
Now try it yourself
Your turn
- Add another
elifbranch for temperatures below 40. - Change
temperatureand re-run until you hit every branch at least once.
Loops
A for loop repeats a block of code once per item in a sequence — like
range(5) (the numbers 0 through 4) or a list of names. A while loop
repeats as long as a condition stays true.
Loops are how you avoid writing the same line ten times. Anything indented under the loop line runs on every pass.
Read this example
for i in range(5):
print("Count:", i)
Now try it yourself
Your turn
- Add a fourth name to the
studentslist. - Change
range(5)torange(0, 10, 2)and predict the output before running it.
Functions
A function is a reusable block of code with a name. You define it once with def,
give it inputs called parameters, and it can hand a result back with
return.
return is different from print — print just displays
something, while return sends a value back so it can be used elsewhere in your
program.
Read this example
def greet(name):
return "Hello, " + name
print(greet("Maya"))
Now try it yourself
Your turn
- Write a function
is_even(n)that returnsTrueifnis even. - Give
adda default value forb, likedef add(a, b=1):, then call it with just one argument.
Data Structures
A list holds an ordered collection — ["Ava", "Leo", "Maya"]. A
dictionary holds pairs of keys and values — {"Ava": 92, "Leo": 88} — so
you can look things up by name instead of position.
Lists have built-in tools like .append() to add an item. Dictionaries have
.items() to loop over every key and value at once.
Read this example
students = ["Ava", "Leo", "Maya"]
students.append("Sam")
for student in students:
print(student)
Now try it yourself
Your turn
- Add two more students to
grades. - Loop over
gradesand print only students who scored 90 or above.
Capstone: Grade Calculator
Time to combine everything — variables, a function, a loop (hiding inside sum()),
and an if/elif chain — into one small but real program.
This calculator takes a list of test scores, averages them, and converts that average into a letter grade.
Read this example
def average(scores):
return sum(scores) / len(scores)
def letter_grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
else:
return "Needs Improvement"
Now try it yourself
Your turn — make it yours
- Add a second student's list of scores and print their average and letter grade too.
- Write a function
class_average(all_scores)that takes a list of lists and returns the overall average. - Change the grade cutoffs to match your own school's grading scale.
That's the whole path — nice work. Questions or want feedback on your capstone?
Email Us Your Code