Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python
#1
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
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 suma

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.
Reply


Messages In This Thread
Python - by Manu - 2011-03-30, 03:19 PM
Python - by Fiel - 2011-03-30, 03:40 PM
Python - by Manu - 2011-03-30, 03:54 PM
Python - by Fiel - 2011-03-30, 04:04 PM
Python - by Manu - 2011-03-30, 07:03 PM
Python - by Fiel - 2011-03-30, 07:16 PM
Python - by Manu - 2011-03-30, 08:11 PM
Python - by Manu - 2011-03-31, 08:16 PM
Python - by Fiel - 2011-04-01, 03:12 AM
Python - by Manu - 2011-04-01, 08:27 PM
Python - by Fiel - 2011-04-01, 08:38 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)