As part of the routine I have used
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
def convertToBase58(num):
sb = ''
while (num > 0):
r = num % 58 # divide by 58 and gives the remainder
sb = sb + ALPHABET[r]
num = num / 58;
return sb[::-1]
This comes back with an error saying that r has to be an integer. But using the % operator seems to define r as integer. What have I missed, please ?
The
rvariable has not been defined as an integer. However, thenumvariable as been defined as afloaton the second iteration of the loop. It's a result of the last line in the loopnum = num / 58.The division operator returns a float. In Python 3.5+ use
//to return an integer.Older versions of Python can use
math.floor