Decimal to Binary in Python

Description

Python program to get decimal number and convert it into binary.
Input:
11
Ouput:
1011

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)

Explanation

Yet to be updated



Interesting Pattern Programs: for more Patterns

Input:
5
Output:
*
**
***
****
*****
****
***
**
*Solution
Input:
5
Output:
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *Solution
Input:
5
Output:
*        *
**      **
***    ***
****  ****
**********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********Solution
Input:
5
Output:
*       *
**     **
***   ***
**** ****
*********
**** ****
***   ***
**     **
*       *Solution
Input:
5
Output:
*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********Solution