Question: It also needs to be in Python 3. Practice Question 1: Binary and Decimal Conversions Write two functions, dec2bin(x) and bin2dec(x) that convert a positive

 It also needs to be in Python 3. Practice Question 1:Binary and Decimal Conversions Write two functions, dec2bin(x) and bin2dec(x) that convert

It also needs to be in Python 3.

Practice Question 1: Binary and Decimal Conversions Write two functions, dec2bin(x) and bin2dec(x) that convert a positive integer from decimal to binary or binary to decimal respectively. For dec2bin the input x is an int, and the output should be a string. For bin2dec, the input x is a string, and the output should be an int. The iterative approach is easiest. If you are feeling adventurous, you could try to come up with a recursive solution. In [13]: def dec2bin(x): remainderList [ while x != 0; (x, remainder) divmod (x,2) remainderList.reverse() return "".join(remainderList) def bin2dec (x): for char in x[:: -1] dec += int(char*(2**i)) return dec Practice Question 2: Passing a Function as a Variable Write a function, stats(f, 1) , that returns what you would get if you call f(1). That is, f is a function that computes a given statistic on a set of data, and 1 is a list of data points To test, use the functions bound, span, and mean from the previous lab. H In [ ]: # Write your answer here. 1n [ ]: DATa2 : 11.for iin range(1m) . % '" 0] DATA2 = [1 for 1 in range(100) if % 3 0] In [ J: stats(span, DATA1) 5 In [ ]: | stats(mean, DATA!) 3.5 In [ ]: Stats (bound, DATA2) == [0, 99]

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!