产生TypeError的基本代码

时间:2018-06-04 00:16:27

标签: python python-2.x dogecoin-api

所以,我希望这段代码具有用户输入的Dogechain地址,并获得该地址的平衡。当我执行此操作时,我收到错误:

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()

1 个答案:

答案 0 :(得分:1)

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

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

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