Hardware Reference
In-Depth Information
Functions can take a number of arguments and return a result. Here you pass an
argument to the
time.sleep()
function, to tell the program how many sec-
onds to wait, and then print the result of
random.choice
.
Figure 5-6 shows the completed code.
FIGURE 5-6
Using modules in Python 3 to create an Inventory program
Check that your program works by saving the ile as
inventory1.py
in the
Documents
folder on the Raspberry Pi
and then clicking Run
➜
Run Module from
the toolbar. Enter input when the program prompts for it. You should see results sim-
ilar to those shown in Figure 5-7.
FIGURE 5-7
Getting a random item from the inventory list, using modules