How Do You Print the Current Price of Bitcoin with Python without Installing New Packages?

Problem scenario
You do not want to install new Python modules. How do you use Python to print out the latest price of Bitcoin?

Solution
Run this program:

import requests
resp = requests.get("https://api.coindesk.com/v1/bpi/currentprice/USD.json")
print(resp.json()['bpi'])

Here is a modified version of the program:

import requests
resp = requests.get("https://api.coindesk.com/v1/bpi/currentprice/USD.json")
print(resp.json()['bpi']['USD']['rate'])

If you want to receive free cryptocurrency by just learning more, try Coinbase; it is ideal for Americans. For Europeans, the platform/company Iconomi.com can allow you to buy crypto or learn more.

Leave a comment

Your email address will not be published. Required fields are marked *