Step 1 of 11
Start here: how do you get through a whole list?
These Python loops and lists exercises start with a problem you meet in any real file: a list of orders, sales or tickets that is far too long to add up or check by hand. Writing one line per item doesn't work when the list has 500 items, or a different number every day.
You just watched a for loop visit each order in turn while the total grew one block at a time. By the end of this lesson you'll write loops like that yourself, to add up, count and pick out the items you need.
What you'll do
- Store many values in one list, and change it with append, insert, remove, pop and sort
- Repeat work with for loops, range() and while loops
- Build totals, counts, the biggest item and new filtered lists with a loop
- Spot the four loop mistakes beginners make most
By the end you can
- predict what a loop will print before you run it
- add up, count and filter a list with a loop of your own
- find and fix a loop that runs but gives the wrong answer
You need print(), variables and if from your first programs, and any Python 3 for the short "Your turn" programs.