Convert decimal to binary

The program asks the user to input the decimal number, In Python we have built in functions to convert decimal to binary, just use bin() function to convert any number. So we don't have to worry about the mathematics behind how to convert decimal numbers to binary.

#Getting input from the user
dec = int(input("Enter the decimal value: "))
print("The decimal value of",dec,"is:",bin(dec)[2:],"in binary.")
Enter the decimal value: 14
The decimal value of 14 is: 1110 in binary.

Post a comment


Your Comment

Email (We dont publish it)


Nothing the first to share wisdom.