Loading lesson…
Variables, loops, and functions are the atoms of Python. Let an AI help you write them while you learn what each line actually does.
Variables hold values. Loops repeat work. Functions package work. Types describe shapes. Learn those four and every Python program becomes readable.
def average(scores: list[float]) -> float:
if not scores:
raise ValueError("scores must not be empty")
total = 0.0
for s in scores:
total += s
return total / len(scores)
if __name__ == "__main__":
print(average([92.0, 88.5, 76.0]))Type hints, a loop, a function, and an explicit error. Four ideas, one file.# Prompt: "Rewrite average() using sum() and a guard clause."
def average(scores: list[float]) -> float:
if not scores:
raise ValueError("scores must not be empty")
return sum(scores) / len(scores)Reading the AI's simpler version teaches you the built-ins you did not know existed.The big idea: write tiny programs, then ask AI to simplify them. The diff between your code and its code is your curriculum.
15 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-progx-python-basics-builders
What is the primary purpose of a variable in Python?
Which Python feature allows a block of code to run multiple times without rewriting it?
What is a function in Python?
What do type hints in Python describe?
What does the type hint `list[int]` indicate?
What is a guard clause?
Why is it important to verify function names that an AI suggests?
What makes code 'idiomatic' Python?
What does it mean to 'package work' with a function?
What is the key difference between `list[int]` (modern syntax) and `typing.List`?
Why might an AI suggest a function like `statistics.meanish()` that doesn't exist?
What is the benefit of writing tiny programs first before asking AI to simplify them?
In the learning strategy described, what is the purpose of examining the 'diff' between your code and AI-generated code?
Which of these is a recommended practice when using AI to help write code?
The lesson mentions that 'four ideas' unlock Python: variables, loops, functions, and types. What do these four concepts have in common?