Question: Python 3 please! 5 = 1 * 2^2 + 0 * 2^1 + 1 * 2^0 Write a function that takes a number and returns

Python 3 please!

5 = 1 * 2^2 + 0 * 2^1 + 1 * 2^0

Write a function that takes a number and returns a list of it's representation in base 2.

def binary(n): """Return a list representing the representation of a number in base 2.

>>> binary(55055) [1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1] >>> binary(-136) ['-', 1, 0, 0, 0, 1, 0, 0, 0] """ "*** YOUR CODE HERE ***"

I was thinking return [int(x) for x in bin(n)[2:]] but it does not work for the binary(-136) sanity check so i guess my code is wrong can someone help me find the correct solution? Thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!