The safety and success of space flight hinges on fidelity to checklists. During the Apollo 13 moon mission efficient use of checklists allowed the crew to survive in space for an entire orbit around the moon with half their space ship shut down to save their meager remaining fuel. This image is of Kevin Bacon in the film Apollo 13 stating to mission control that he has completed the checklist items on page 15.

The glory of python lists

Start Here: Jump to a section

wb_incandescentLearning goals
wb_incandescentList basics
wb_incandescentMini-project: Checklist manager

Learning goals

Essentials of lists

Lists are a way of storing data values in an ordered sequence and provide a backbone data structure for many software components. Lists are mutable, meaning we can create them and then edit their contents through the use of methods (i.e. functions) such as append(x) and remove(x).

Code along with the following sample python where we create lists literally and with append() and then display their contents:

list basics

official documentation

python.org provides a comprehensive page summarizing the data structures essentials in python, starting with lists and running through dictionaries! Dedicate a few hours to carefully creating code that demonstrates the operations on lists described in the documentation.

List indexes start at zero! 0

A critical behavior of list operations in python (and many other languages) is that list items are numbered starting at an index of 0. The second item in a list has an index of 1, and so forth. When accessing list items, therefore, our code must be careful not to try to access the index of an element that is not in the list. This often happens because we start counting at 1 and ask for what we think is the last item in a list, but in reality the requested item doesn't exist.

Study the following example and output by creating your own list and trying to access its items by index. Try accessing an item that is not in the list and see that you, too, can get an index out of range error.

code code

arrow_upward back up to contents


Checklist manager mini-project

To exercise your list prowess, create a program that allows users to create and manage a checklist of items to use in conducting some task that's interesting to you. The checklist could also be more like a list of steps to make something such as cooking recipe or a craft.

Specifications

Your checklist manager should meet these specifications:

  1. Display a program menu with numbers corresponding to the following actions the user can undertake on their checklist: View the list, add to the end of the checklist, remove an item from the checklist by name, remove an item by index, and end the program
  2. Display each item in the checklist preceded by its index
  3. Prompt the user to enter a new item which then gets appended to the end of the checklist. Program displays a confirmation message
  4. Prompt the user to enter the exact text of an item to remove from the checklist. Program should confirm when it is done. You may optionally gracefully fail if the user enters an item that is not in the list using try and except
  5. Prompt the user to enter the index of an item to remove and then confirm that the item was removed. The program should fail gracefully if the user enters an index out of bounds of the list's index range.
  6. When the exit code is given, exit the program with a message
Figure 4: Sample program interaction
sample program interaction sample program interaction sample program interaction sample program interaction

Extension exercises

The following features can be implemented in any order or only partially as a way to continue your list learning.

arrow_upward back up to contents


(c)2023 technologyrediscogvery.net | content can freely reproduced according to the site's content use agreement.