tips.md basics.html variables.html functions.html loops.html lists.html project.html
// putting it together

A Small Project

~/lessons/project.html

Reading about variables, functions, loops, and lists one at a time is fine, but none of it really sticks until you use them together on one actual problem. Here's a small grade-calculator program that uses all four. Read through it slowly, line by line, and try to explain each line to yourself before reading the explanation below it.

def get_letter_grade(score): if score >= 90: return "A" elif score >= 80: return "B" elif score >= 70: return "C" else: return "F" student_scores = [95, 72, 88, 61, 100] letter_grades = [] for score in student_scores: grade = get_letter_grade(score) letter_grades.append(grade) for i in range(len(student_scores)): print(str(student_scores[i]) + " -> " + letter_grades[i])

Run through what this actually does. First, a function is defined — get_letter_grade — that takes one score and returns a letter based on which range it falls in. Defining it doesn't run it yet, it just makes it available to call later.

Then there's a list of scores, and an empty list, letter_grades, that starts with nothing in it. The first loop goes through every score, calls the function on it, and appends the result to letter_grades. By the end of that loop, letter_grades has exactly as many items as student_scores, in the same order.

The second loop is a bit different — it loops over a range of numbers instead of the list directly, from 0 up to (but not including) the length of the list. That gives us an index i we can use to pull the matching item out of both lists at once, so we can print them side by side.

Why it's built this way

You could technically write this whole thing without a function, just repeating the if/elif/else block inside the loop directly. It would work. But pulling it out into get_letter_grade means the grading logic has one clear name and one clear home. If the grading scale changes later, you fix it in exactly one place instead of hunting through the program for every spot it was copied.

This is a small example of a bigger idea: functions aren't just about avoiding repeated typing, they're about giving a chunk of logic a name and a boundary, so the rest of the program can just say "get the grade for this score" without needing to know how that decision gets made.

Try changing it yourself

The best way to actually learn this is to break it on purpose and fix it. A few things worth trying on your own, in order of difficulty:

// 1. Add more scores to student_scores and see it still work // without changing anything else // 2. Add a "B+" grade for scores 85 and above, between // the existing A and B ranges // 3. Add a function called average(scores) that returns // the average of a list of numbers, and print it below // the existing code // 4. Change the second loop to only print scores that // got an "F", skipping the rest

None of these require anything you haven't already learned in the earlier lessons. If you get stuck, that's normal — go back to the relevant lesson, re-read the small example there, and try again. That loop of "try, get stuck, go back, try again" is genuinely most of what learning to code actually looks like, for everyone, not just beginners.

Where to go from here

Once this kind of program feels comfortable rather than confusing, you're past the very beginning stage. From here, natural next topics are dictionaries (key-value pairs, similar to a list but looked up by name instead of position), reading input from a user, working with files, and eventually building something with a real purpose — a to-do list app, a simple game, a script that automates something tedious you do by hand. Pick something you actually want to exist, and build toward it. That's a far better teacher than any lesson page, including this one.