Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

Students also viewed these Databases questions

Question

=+Are there shop stewards?

Answered: 1 week ago