Notes

This task is best preceded by a follow-me activity geared towards producing this result in incremental stages.

Students respond to key questions with their own code and then share ideas as the code is built.

Start with , then y, and then to use for further processing.

  • printing items in the array
  • searching for an item in the arra
  • grabbing the index of an item in the array
  • replacing an item in the array

Discuss the difference between including the code at line 13 or 19.

The Tool Store

 

Construction workers need tools to work. They borrow tools from the Tool Store.

The available tools are:

  1. hammer
  2. brush
  3. screwdriver
  4. glue gun
  5. pliers

A program is required to allow a worker to borrow a tool.

All available tools are stored in an array eg:

toolStore = ["hammer", "glue gun", "tape measure", "taken", "brush", "brush", "taken", "brush"]

To borrow a tool, the worker has to enter the type of tool needed into a computer program eg:

tool = input("What kind of tool would you like to borrow?")

The program searches the array for the tool. If it is available, it is replaced by the word "taken" and a message appears Please take your tool.

Note - only 1 tool can be taken at a time!

Otherwise a message Tool unavailable is displayed and the user is prompted to enter the name of another tool.

Design a program that will allow worker's to borrow tools from the tool store.

Adaptation

Adapt your program so that it offers a choice of:

  1. Borrow a tool
  2. Return a tool

If the user chooses 1, the program works as before.

If the user chooses 2, if there is a "taken" in the Tool Store array, the user is asked which tool is being returned and it is placed in the tool box, replacing "taken".

The menu then reappears and the worker can repeat the process.

Design this adaptation.

Testing and validation

Are there any opportunities to include validation checks in these coding assignments?

Make sure you test your code with a variety of data to make sure it works as expected.