Browser lab15 min+60 XP

Lists

One variable, many values. A list keeps items in order, like a playlist.

0% done

Code runs right here in your browser. Nothing to install.

TASK 1

Learn it

Key idea

A list keeps many values in order inside one variable.

Key words
squad"Nova"0"Kai"1"Mira"2scores12009511402len(squad) = 3sum(scores) = 355max(scores) = 140
Two lists, each with numbered positions starting at 0.

A list stores many values, in order, in one variable. Write the items inside square brackets, separated by commas: scores = [12, 45, 7]. A list can hold any types, even a mix.

len(scores) gives the number of items. print(scores) shows the whole list. An empty list is [].

Lists are mutable, which means you can change them after creating them: add items, remove items or replace them. You will do all of that in the next rooms.

Real life linkYour music playlist is a list: songs in a set order, and you can add, remove and shuffle them.
Example code
squad = ["Nova", "Kai", "Mira"]
scores = [120, 95, 140]
print(squad)
print("Squad size:", len(squad))
print("Top score:", max(scores))
print("Total:", sum(scores))
TASK 2

Try it yourself

+10 XP

Make a list called games with your 4 favourite games (as strings). Print the list and then I listed 4 games using len().

Create a free account to start this lab

Sign in to write, run and check your code here. Your progress, XP and code are saved to your account. No card needed.

TASK 3

Capture the flag

+10 XP

What does len([5, 8, 2, 9]) return?

Create a free account to start this lab

Sign in to answer the flag question. Your progress, XP and code are saved to your account. No card needed.

HOMEWORK

Weekly steps

+20 XP

Store 7 daily step counts in a list called steps. Print the total with sum(), the best day with max(), and the average rounded to a whole number with round(). Labels: Total:, Best:, Average:.

Create a free account to start this lab

Sign in to do this homework and have it checked. Your progress, XP and code are saved to your account. No card needed.