Decimal to Binary in Python

Python program to get decimal number and convert it into binary.

Sample Input 1:

11

Sample Output 1:

1011

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#write your code here

Program or Solution

				
			
					
binary_num,base=0,1
decimal_num=int(input("Enter a Decimal number:"))
while (decimal_num > 0):
    remainder = decimal_num % 2
    binary_num = binary_num + remainder * base
    decimal_num = decimal_num // 2
    base = base * 10
print(binary_num)

			
				
			

Program Explanation

Yet to be updated

Comments