Lesson 146 of 1455
Python Loops & Conditionals — Let AI Draft, You Decide
If-statements and loops are where programs come alive. You'll write both kinds, then see where AI autocomplete helps and where it lies.
Builders · AI-Assisted Coding · ~18 min read
If this, then that
A conditional lets your program make choices. An if-statement runs a block of code only when a condition is True. An else runs when it is False. An elif is 'else if' — check another condition.
Python uses indentation, not braces. Four spaces is the standard.
score = 87 if score >= 90: grade = "A" elif score >= 80: grade = "B" elif score >= 70: grade = "C" else: grade = "try again" print(f"You got a {grade}.")Loops: doing a thing many times
for-loops are for 'I know how many times.' while-loops are for 'until X happens.'
# for-loop over a range of numbers for i in range(5): # 0, 1, 2, 3, 4 print(f"Step {i}") # for-loop over a list names = ["Ava", "Ben", "Cy"] for name in names: print(f"Hi, {name}!") # while-loop: run until a condition turns False countdown = 3 while countdown > 0: print(countdown) countdown -= 1 print("Go!")Truthiness — Python's clever shortcut
In Python, empty containers are False. This makes if-statements read like English.
# These values are all 'falsy': they act like False in conditions for value in [0, "", [], None, False]: if not value: print(f"{value!r} is falsy") # Everything else is 'truthy' items = ["apple", "banana"] if items: # same as: if len(items) > 0 print("We have items!")Mini-exercise: FizzBuzz
- 1Write a loop from 1 to 20
- 2If the number is divisible by 3, print 'Fizz'
- 3If divisible by 5, print 'Buzz'
- 4If divisible by both, print 'FizzBuzz'
- 5Otherwise print the number
Compare the options
| Task | Autocomplete is great | Autocomplete often lies |
|---|---|---|
| Standard FizzBuzz | Yes | No |
| Domain-specific rules | Rarely | Often — invents fake field names |
| While-loop termination | Sometimes | Forgets to decrement the counter |
Key terms in this lesson
Big idea: conditionals and loops let the computer make millions of small decisions. AI drafts them fast — but you are the one who owns whether the logic is actually right.
End-of-lesson quiz
Check what stuck
8 questions · Score saves to your progress.
Lesson help
Questions are best handled with a grown-up here.
For this age range, Tendril keeps freeform AI chat paused until parent/guardian consent and child-safe moderation are fully verified. Use the quiz, notes, and related lessons below, or ask a parent, guardian, teacher, or librarian to work through the question with you.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Builders · 30 min
Bash and Shell With AI
The terminal is where real work happens. Pipes, variables, and loops in bash are a superpower — and AI is surprisingly good at shell one-liners.
Builders · 25 min
What Does AI-Assisted Coding Even Mean?
AI-assisted coding is not magic and not cheating. It is a new way of working where a model drafts, you decide. Let's draw a map before we start building.
Builders · 30 min
Your First Copilot-Style Completion
Let's actually feel what autocomplete is like. Write a comment, pause, and watch a full function appear. Then learn what to do next.
