Space Python Loading Python…

Backup that isn't

Fix the codeMedium 3 stages

Before trying out a change to the crew, the planner made a backup of the roster and experimented on the backup. When the experiment was over, the live roster had changed as well, and Tanaka had quietly disappeared from it.

Predict what the code prints, find out how the backup reached the live roster, fix it, then plan a real crew change on a copy.

Don't run the code yet. Read it and decide what it will print on its first line. Write your guess in prediction, at the top, between the quotes. Then run it and compare.

Any guess passes this stage: the point is to think before you run. After you check, you'll see your prediction next to what Python printed.

Which names will the live roster hold after the change to the backup?

Predict, then run
Leave the program as it is

Finish stage 1 to unlock this stage.

Investigate. Find out whether backup and crew are the same list with backup is crew, and store True or False in same_list. Then store how many names crew holds after the remove in crew_size_after. Remove any lines you added before you check.

Modify. Make backup a real copy, so the change to it leaves crew alone. It must print:

Live roster: ['Okafor', 'Lindqvist', 'Tanaka', 'Kowalska']
Backup: ['Okafor', 'Lindqvist', 'Kowalska']
Find the shared list
Make a real copy

Finish stage 2 to unlock this stage.

The next rotation swaps Tanaka for Moreau. Build the planned roster as a separate list: copy crew, remove Tanaka from the copy and add Moreau at the end. Then print both:

Current: Okafor, Lindqvist, Tanaka, Kowalska
Planned: Okafor, Lindqvist, Kowalska, Moreau

The current roster must not change.

Plan on a copy
The current roster stays
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:].