0

所以,我希望这段代码让用户输入狗狗链地址,然后我得到那个地址的余额。当我执行这个我得到错误:

url = "https://dogechain.info/api/v1/address/balance/"+ a

错误:

TypeError: cannot concatenate 'str' and 'int' objects

代码:

import requests

def main():
    a = input("Address?")
    url = "https://dogechain.info/api/v1/address/balance/"+ a
    response = requests.get(url)
    bal = response.json()[0]["balance"]
    print("Balance:",bal)

main()
4

1 回答 1

1
url = "https://dogechain.info/api/v1/address/balance/" + str(a)

或者

url = "https://dogechain.info/api/v1/address/balance/{}".format(a)

@Ryan O'Donnell 下面的评论解释了原因,谢谢。

于 2018-06-04T00:25:03.390 回答