Question: Question 3 (4 points): Checking Valid Inputs Write a function valid(f, 1) that, given a function f and a list of potential inputs 1, returns

Question 3 (4 points): Checking Valid Inputs Write a function valid(f, 1) that, given a function f and a list of potential inputs 1, returns a list, tuple, or set of the elements of 1 that are valid inputs to f. How will you know if something is a valid input to f? If you call f on the element and an exception is thrown, you know it was not a valid input review practice question 3 where we try to use the hex2dec0 function, but ignore any error we get if the input was not valid. For instance, if f is the abs) function, it can only accept integers and floating point numbers. If it is the max) function, it can only accept lists or tuples, if it is the sqrt) function, it can only accept non-negative numbers, etc... In [ ]: # Write your answer here. In : from math import sqrt In from math import asin In valid(chr, , 10, 123.3, 2**21])[10 In def onlyStrings (x): valid(sqrt, [-3, 0, 51) [0, 5] == valid ( asin, [0.3, -0.1, -1, 1, 'cat', '1', 1.3]) [o.3, -0.1, -1, 1 - if type(x) - str: return True else: raise UserWarning valid(onlyStrings, l'cat', 123, [1, 2, 311) l'cat
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
