Loop Through a List
FreePrint each fruit in <code>fruits</code> on its own line.
Show the solution
for fruit in fruits: print(fruit)
Right — a for loop runs its indented block once for every item.
Practice by topic / Python & code / Python
Python is the most popular language for automating work: cleaning data, renaming files, crunching numbers. Each exercise runs your real code in the browser and checks it. These 5 exercises build up step by step, starting with loop through a list, pass or fail, grade bands.
3 of 5 free · no sign-up needed · instant feedback
Print each fruit in <code>fruits</code> on its own line.
for fruit in fruits: print(fruit)
Right — a for loop runs its indented block once for every item.
Create <code>result</code>: <code>"Pass"</code> if <code>score</code> is 50 or more, otherwise <code>"Fail"</code>.
if score >= 50: result = "Pass" else: result = "Fail"
Good — if/else is Python's IF(). Watch the boundary: >= 50 includes 50 itself.
Create <code>grade</code> from <code>score</code>: <code>"A"</code> for 80+, <code>"B"</code> for 65–79, <code>"C"</code> for 50–64, otherwise <code>"F"</code>.
if score >= 80: grade = "A", then elif score >= 65: grade = "B", elif score >= 50: grade = "C", else: grade = "F"
Exactly — if/elif/else checks top-down and stops at the first match, like nested IFs (or IFS).
Create <code>big</code>: how many amounts in <code>orders</code> are over 1000.
Solution and instant grading: open it in the practice app (use one of your 20 free picks, or Pro).
Try it in the live editor →Create <code>running</code>: a list where each value is the total of <code>sales</code> so far (<code>[100, 300, 350, ...]</code>).
Solution and instant grading: open it in the practice app (use one of your 20 free picks, or Pro).
Try it in the live editor →