-1

So yeah I'm trying to figure a way on how to change a decimal into a binary in python

Kroolkid
  • 1
  • 1

2 Answers2

3

How about bin:

>>> bin(42)
'0b101010'
cnicutar
  • 178,505
  • 25
  • 365
  • 392
1
In [1]: def dec2bin(n):
   ...:     if not n:
   ...:         return ''
   ...:     else:
   ...:         return dec2bin(n/2) + str(n%2)
   ...:     

In [2]: dec2bin(11)
Out[2]: '1011'
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241