I tried writing a basic program that converted binary to decimal. However, it's not working. Where did I go wrong? What am I missing. Thanks for the help in advance.
n=int(raw_input(' '))
while n = 1:
k = n % 10
z= 0
w=0
w = k * (pow ( 2, z)) + w
z = z+1
n/10
print w
1 Answer 1
First of all, you used = for a comparison test. Instead, I think that you want to use != (not equal):
while n != 1:
= is only used for assignment.
Also, the line:
n/10
does nothing. Instead, it should be:
n /= 10
which is equivalent to:
n = n / 10
Sign up to request clarification or add additional context in comments.
Comments
lang-py
int(number, base)?int('10010', 2) == 18print int(raw_input(' '), 2)