-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

2

How about bin:

>>> bin(42)
'0b101010'
cnicutar
  • 172,020
  • 25
  • 347
  • 381
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
  • 104,525
  • 25
  • 135
  • 234