Week 4

Libraries

A library is functions someone else already wrote. You import them, or install them first and then import them.

Import loads a library. From imports one name out of it, so you can call that name without the library's prefix. Random can pick from a list, shuffle a list, or give an integer between two ends, and both ends count. Statistics can average a list. Those two ship with Python.

Sys.argv is the list of words typed after python. Item 0 is the program's own file name. If you read an item that is not there, you get an IndexError, so check the length first or stop with sys.exit. A slice such as argv[1:] drops the file name and keeps the rest.

Packages that are not built in are installed with pip, then imported the same way. Requests gets text from the web. That text is often JSON, which Python turns into nested dictionaries. You open them by key, outer box first. A fresh example is the cafe menu toy on this page, not the bitcoin problem.

The idea
Bring in a tool, then call it Import a tool Hand it something Use what it returns

Try this first

A die. Not a problem set.

Both ends can come up. Roll until you have seen 1 and 6.

A cafe menu. Not a problem set.

Open the outer box, then the inner one. The price is inside.

Words after a file name. Not a problem set.

Word 0 is always the file. Anything you type starts at 1.

    Problems

    A gentle order is Emojize, Guessing Game, Little Professor, Adieu, Figlet, then Bitcoin. The course does not require that order. You still submit all six.