所以,我希望这段代码具有用户输入的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()
答案 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的评论解释了原因,谢谢。