#π API - I need help learning how to start my homework
7 messages Β· Page 1 of 1 (latest)
@potent acorn
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
import requests # used to send HTTP requests
import time # use for sleep
# URL for CoinDesk Bitcoin Price Index
# The coindesk API is accessed through URL calls
url = "https://api.coindesk.com/v1/bpi/currentprice/BTC.json"#
# Send a GET request to the URL
response = requests.get(url) # returns as response object
#
# Parse the JSON response
data = response.json() # converts to a python dict
# Extract the current price of Bitcoin in USD
# You can look at the JSON result to see how this can be done.
price_usd = data['bpi']['USD']['rate']
print(price_usd)
# How might this be looped?
time.sleep(60)
response = requests.get(url)
data = response.json()
price_usd = data['bpi']['USD']['rate']
print(price_usd)
# Create a simple game that lets you guess if the price
# of bitcoin will go up or down in the next minuite.
# ideas
# - Could you pick between a set of cyrpto currencies?
# - Have a count down (maybe in 5 second increments)
# - Keep a score
# - link to TK inter / GUI
# - any other ideas!
could you start simple, by asking the user if the price will go up or down
then sleep for a minute, check and report the results
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.