0

помогите преобразовать response_json[0]['price_usd'] в целое число

import requests

TICKER_API_URL = 'https://api.coinmarketcap.com/v1/ticker/bitcoin'


response = requests.get(TICKER_API_URL)
response_json = response.json()

print(response_json[0]['price_usd'])

Заранее спасибо.

2 ответа 2

0
import requests

TICKER_API_URL = 'https://api.coinmarketcap.com/v1/ticker/bitcoin'


response = requests.get(TICKER_API_URL)
response_json = response.json()
price_s = response.json()[0]['price_usd']
price = int(price_s[:price_s.find('.')])
print(price)
1
  • Мое решение мне кажется проще (см. мой ответ). 1 фев 2020 в 15:02
0
import requests

TICKER_API_URL = 'https://api.coinmarketcap.com/v1/ticker/bitcoin'


response = requests.get(TICKER_API_URL)
response_json = response.json()

print(int(float(response_json[0]['price_usd'])))

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.