python - Write a program to convert decimal to binary. Email ThisBlogThis!Share to TwitterShare to Facebook Reactions: Labs 2 Comments
n=int(raw_input("enter number"))
ReplyDeletei=0
s=0
while (n>0):
r=n%2
s=s+pow(10,i)*r
n=n/2
i=i+1
print s
enter number123
1111011
n=int(input('please enter the no. in decimal format: '))
ReplyDeletex=n
k=[]
while (n>0):
a=int(float(n%2))
k.append(a)
n=(n-a)/2
k.append(0)
string=""
for j in k[::-1]:
string=string+str(j)
print('The binary no. for %d is %s'%(x, string))