Basic code producing TypeError

161 Views Asked by At

So, I want this code to have user input Dogechain address, and I get the balance of that address. When I execute this I get error:

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

Error:

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

Code:

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

There are 1 best solutions below

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

or

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

And @Ryan O'Donnell's comment below explains why, thanks.