Control flow and syntax, compared to what you know
Block structure: indentation, not braces
Most languages mark a block with braces:
if (isReady) {
printf("this is inside the block\n");
printf("so is this\n");
}
printf("this is not\n");Python uses indentation instead — no { }, and the colon (:) opens the
block:
Indentation isn’t a style choice here — it’s part of the syntax. Mixing levels inconsistently fails to parse:
There’s also no explicit type declaration on variables — Python is
dynamically typed, so x = 5 and x = "five" are both just valid
assignments, no int x or var x: string required. (We’ll come back to
when you’d want type hints later in the module.)
if / elif / else
Same logical structure as most languages, different keyword for “else if”:
for loops — iterate over values, not a counter
If you’re coming from a C-style for (int i = 0; i < n; i++), Python’s for
works differently: it iterates directly over an iterable — anything that
can hand out its items one at a time (a list, a string, a range of numbers).
There’s no index variable unless you explicitly ask for one.
tool is each value from the list in turn, not a position. The
f"..." string is an f-string: prefixing a string with f lets you
embed expressions directly inside { }, evaluated and inserted at runtime —
Python’s equivalent of JS template literals or C#’s interpolated strings,
and more concise than "available: " + tool or .format().
When you specifically need a counter instead of (or alongside) values,
range() generates one — it’s an iterable of numbers, not a special loop
syntax:
while loops and no ++
while works like you’d expect — condition checked, loop runs while true.
One difference: Python has no ++/-- increment operators.
attempts++ isn’t invalid-but-different — it’s a straight SyntaxError,
since ++ isn’t an operator Python defines at all.
What happens if you mix inconsistent indentation levels in the same block, like the example above?
Write `first_available_tool(requested_tools, available_tools)`: loop through `requested_tools` in order, and return the first one that's also present in `available_tools`. If none match, return "none".