Space Python Loading Python…

List Indexing and Modification

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Crew roster

Write the codeEasy 2 stages

Print the commander, the newest member and the crew size from a list with [0], [-1] and len(), then add the second in command and the whole roster joined into one line.

Start the challenge

Last five readings

Write the codeEasy 2 stages

Show only the five most recent CO2 readings with the slice [-5:], as a dashboard does, then add a new reading and print how much the level changed across the window.

Start the challenge

Missing index

Fix the codeEasy 3 stages

readings[5] on a list of five readings stops with an IndexError. Predict it, work out the valid indexes with len(), fix it with [-1], then print the first, middle and last readings for any length.

Start the challenge

Backup that isn't

Fix the codeMedium 3 stages

backup = crew gives one list two names, so removing someone from the backup removes them from the live roster too. Predict it, prove it with is, fix it with copy(), then plan a crew swap on a real copy.

Start the challenge

Discussion

Stuck on this example or want to go further? Ask here, or see what others asked.

Log in to ask and reply.

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:].