Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 valid(sqrt, [-3, 0, 51)0, 51 In [ : from math import asin valid ( asin, [0.3, -0.1, -1, 1, 'cat', '1', 1.31) [o.3, -0.1, -1, - In valid(chr, , 10, 123.3, 2**21])[10 In def onlyStrings (x): 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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions