Question: Hello please solve the following in python. Make sure your code passes all the tests for a thumbs up. Thanks. Create a piece-wise function pwfun(),

Hello please solve the following in python. Make sure your code passes all the tests for a thumbs up. Thanks.

Hello please solve the following in python. Make sure your code passes

all the tests for a thumbs up. Thanks. Create a piece-wise function

Create a piece-wise function pwfun(), defined in the following way: pwfun (x)= Your python function should be able to accept both a single numeric value (float or int), and a list of numeric values. The output should be either a single numeric or a list, depending on what the input is. Round your output values to 2 decimal places. Also, whenever the output entry is an integer (in mathematical sense), it should be converted into an value. For example, if then should return (NOT [4.,24.],whoseentriesandarefloats) Here are some input vectors and what you should get as a corresponding output. pwfun (-1) pwfun ([2,0.5,3]) [2,0,8] x=[3.0,2.5,1,0,1,2,3.2] \#\# note the output of the first two floats pwfun(x) [4,3,,,,3,9.24] MAKE SURE YOUR CODE PASSESTHE FOLLOWING TESTS: \#\# testing whether the entries are of appropriate type import numpy as np x=[3.0,2.3,7/2,2.5,1.4] out = pufun (x) \# components with indices 1 and 4 (i.e. 2nd and the last component) \#\# should be real, while the rest should be integers assert type ( out [])== int \# should be of int type assert type(out[1]) in [float, np.float64] \#\# should be either float or numpy. float64 type assert type ( out [2])= int assert type(out[3]) == int assert type(out[4]) in [float, np. float64]

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!