python · level 1 · unit 6 · lesson 4
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Lists can tell you the biggest and the smallest.
Lists can answer questions. finds the biggest value and finds the smallest. Give them a list of temperatures and they find the hottest and the coldest day for you.
in asks "is this in the list?" and gives back True or False. .count() tells you how many times a value turns up.
You can also search by hand with a loop and an if, checking each item in turn. max() and min() do that work for you.
temps = [14, 19, 11, 17]
print(max(temps), min(temps))
print(19 in temps)
print(temps.count(17)) max() and min() give back the value itself, not its index.
guess first
Is the milk in the fridge?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
fridge = ["milk", "cheese", "jam"]
print("Milk" in fridge)
your turn
Your turn. Find your best and worst score.
Type four scores of your choice, then press run to see the best and the worst.
fix it
This should find the coldest day, 4. Can you fix it?
- It prints 0, but 0 is nowhere in the list. Where did that 0 come from?
- coldest starts at 0, and no temperature is below 0, so it never changes.
- Start with the first item instead: coldest = temps[0]. Or print min(temps).
nailed it
you can find anything in a list now. :D
max()finds the biggest value,min()the smallest.inanswers True or False: is it in the list?.count()tells you how many times a value appears.
new words in your collection
- max
- min
This lesson isn’t saved. A free account remembers every lesson you finish.