Space Python Loading Python…

Crew roster

Write the codeEasy 2 stages

The crew of Python One is stored as a list of names, in the order they joined. The commander is always first, and whoever joined last is at the end. The mission board shows who is in charge, who is newest and how many people are on board.

Read those facts out of the list, then add the full roster to the board.

Print the commander, who is first in the list, the newest member, who is last, and the crew size:

Commander: Okafor
Newest member: Kowalska
Crew size: 4

Indexes start at 0, as in strings. crew[-1] is the last item whatever the list's length, and len(crew) counts the items.

Read the list
Works for any crew

Finish stage 1 to unlock this stage.

Add the second in command, who is second in the list, and the whole roster on one line:

Commander: Okafor
Newest member: Kowalska
Crew size: 4
Second in command: Lindqvist
Roster: Okafor, Lindqvist, Tanaka, Kowalska

", ".join(crew) joins the names with a comma and a space between them. Printing crew itself would show the brackets and quotes too.

Show the whole roster
Works for any crew
You're not logged in, so your progress is kept in this browser only. Log in to save it, and to use hints and solutions.

Hints

List Indexing and Modification

list-indexing-modification.py
# Lists - reading and changing items by position

# Galilean moons, ordered by distance from Jupiter
moons = ["Io", "Europa", "Ganymede", "Callisto"]

# Index 0 is the first item, not 1
print("Closest:", moons[0])
print("Second:", moons[1])

# Negative indexes count back from the end
print("Farthest:", moons[-1])
print("Last index:", len(moons) - 1)

# Slicing: start included, stop excluded
print("Next stops:", moons[1:3])

# Apollo 13: Mattingly was grounded 3 days before launch
crew = ["Lovell", "Mattingly", "Haise"]
crew[1] = "Swigert"
print("Flight crew:", crew)

# append() adds one item to the end
moons.append("Valetudo")
print("After append:", moons)

# remove() searches by value, not by index
moons.remove("Io")
print("After remove:", moons)

# Every position shifted down by one
print("New first:", moons[0])
Open the full example
script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].