[practice]Python Basics
Loops & Conditionals
# theory
if/elif/else evaluates top to bottom and stops at the first match:
if score >= 90: grade = "A"
elif score >= 80: grade = "B"
elif score >= 70: grade = "C"
else: grade = "F"
Comparison operators you'll use: ==, !=, <, >, <=, >=, and in for membership ("apple" in fruits).
for iterates anything iterable:
for fruit in fruits:
print(fruit)
range() makes integer sequences. range(5) is 0..4, range(2, 6) is 2..5, range(0, 10, 2) steps by 2.
enumerate() when you need the index alongside the value:
for i, fruit in enumerate(fruits):
print(f"{i}: {fruit}")
while for "keep going until":
count = 0
while count < 5:
print(count)
count += 1
Rule of thumb: for when the iteration count is knowable up front, while when it depends on runtime state.
# examples [3]
Loop through and count items meeting criteria
Track position and value together
Create new lists based on conditions
# challenges [2]
# project
# project-challenge
thread: SF Permits Analysis · reward: 50 xp
# brief
The planning department needs a quick count of active vs completed permits. Count how many permits are 'issued' versus 'complete' to generate a status report.
# task