Q:

Why do I get 'int is not subscriptable' error message?

I'm making a binary to decimal converter, and we can't use int() or bin(). I THINK I've gotten the code correct, except it keeps telling me "int is not subscriptable"! HELP!
binaryNum = input("Enter a binary number: ") decimalNum = 0 count=0

while(int(binaryNum))>0:
    count=count+1
    binaryNum=int(binaryNum)//10
    power = count

while power >= 0:
    if int(binaryNum[power]) == '1': #here is the problem
        decimalNum += 2**power
        power -= 1

print(decimalNum)

A:

You can do it simply like this, ( ord function will return ASCII value of the given number therefore if you subtract the number from 48 which is ASCII value of '0' you will convert the number easily )
binary = input('enter a number: ')
decimal = 0
for digit in binary:
    digit = ord(digit) - 48 
    decimal = decimal*2 + digit
print(decimal)

if you don't want to use extra functions you can do it like  this
binary = input('enter a number: ')
decimal = 0
for digit in binary:
    digit = 1 if digit == '1' else 0
    decimal = decimal*2 + digit
print(decimal)

And your problem reason is you can't iterate a integer
while(int(binaryNum))>0:
    count=count+1
    binaryNum=int(binaryNum)//10 ### here you assign binaryNum as integer
    power = count

while power >= 0:
    if int(binaryNum[power]) == '1': ### and you cant iterate binaryNum because it is an integer
        decimalNum += 2**power
        power -= 1

