Shahaed
Shahaed

Reputation: 460

Basic Binary to Decimal Conversion Program not working (Python)

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

Upvotes: 0

Views: 132

Answers (1)

user2555451
user2555451

Reputation:

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

Upvotes: 2

Related Questions