Week 4

Bitcoin Price Index

One number from the command line, then a dictionary that arrived from the web.

You type

How many bitcoins, as one number after the file name.

The tool
The price sits inside an inner box the response the coin a price
What comes out

A dollar cost. A missing or non-numeric argument stops the program.

The question, more slowly

The question is: one command-line number says how many bitcoins, and you print the dollar cost. Missing argument and non-numeric argument are two different exit messages, both written in the spec. The price comes from CoinCap. You need an account and an API key. The URL shape and a sample JSON response are on the spec.

The price is text, nested inside an object, which is nested inside the response. Open the outer key, then the inner key, then turn the text into a float. Multiply by the count. The spec gives the print format: a dollar sign, thousands separators, four decimal places. If the request fails, catch the exception the spec names and exit.

check50 substitutes its own response, so its price will not match the live price. Your code should not special-case that. Paste the sample JSON into a dictionary and print only the price before you add the network.

Before you code

Paste a made-up menu into a dictionary and print only the inner price. The toy on this week does that. The spec shows the real boxes and the print format. You also need the account and key the spec describes.