← All missions

πŸ“‹ Roll Call

πŸŽ’ Organizing Stuff with Lists

1) What do I need to do?

🎯 Your mission: Hero roll call

Make a list of 4 heroes. Use a for loop to print "Calling ___!" for each one.

2) What do I need to know?

for item in list

A for loop can walk through a list, giving you each item in turn.

for hero in team: β€” each time round, hero holds the next name.

🧰 Your toolkit for this mission

Everything you need to know to finish this lesson on your own:

for item in list

Visit every item in turn.

How to write it: The loop variable holds the current item each time round.

for hero in team:
    print("Calling", hero + "!")

Running total

Add everything up.

How to write it: Make total = 0 before the loop, then total = total + item inside.

total = 0
for s in scores:
    total = total + s
print(total)

sum() / max() / min()

Built-in shortcuts for number lists.

How to write it: max(scores) gives the biggest, min the smallest, sum the total.

print(max(scores))

Think about it

Look at this code. What happens next, and why? Say it in your own words.

for hero in team:
    print(hero)
print("Done")
Watch & explore β–Ά

Power-up: for item in list

See it happen

1 / 3
team = ["Bolt", "Nova"]
for hero in team:
hero
Bolt

The loop variable holds the first item.

3) Run the code & terminal output

Code Lab 🐍Playground β€” experiment freely!
Hero Terminal

Press β–Ά RUN and your program's messages appear here!

Equipment Vault
Equipment Vault
Your superhero companion

Captain Py

Our next adventure is yours to create.