2011-03-30, 03:19 PM
Sup, I'm beginning to learn python, only know the very very very very basics so far, and I'm creating this thread so I (and other people if they need) can ask for help on things they can't do.
I'm kind of stuck on this simple and probably 'python 101' problem, it's to make a binary number a regular one.
What I wrote (ignoring my spanish variable use) is
According to me this asks for the binary code, and then should transform it, but something I can't find is wrong with it and I always get 0 as result, I've tried changing some things but I can't get it right.
My first exam is on saturday so I'll probably ask more stuff about basic coding like this.
I'm kind of stuck on this simple and probably 'python 101' problem, it's to make a binary number a regular one.
What I wrote (ignoring my spanish variable use) is
Code:
suma=0
n=str(raw_input('ingresa codigo binario: '))
x=len(n)-1
for i in range (-1,-(len(n))):
q=(n[i])
suma=suma+(int(q))*(2**x)
print suma
x=x-1
print sumaAccording to me this asks for the binary code, and then should transform it, but something I can't find is wrong with it and I always get 0 as result, I've tried changing some things but I can't get it right.
My first exam is on saturday so I'll probably ask more stuff about basic coding like this.

