Question: Practice Question 2: prodEvenBetter) Let's build on the prodBetter(1) function. Say that '3.14' is an element of the list. We want our function to be

Practice Question 2: prodEvenBetter) Let's build on the prodBetter(1) function. Say that '3.14' is an element of the list. We want our function to be able to multiply by this number. However, we obviously don't want to convert the string kittens' to a number (general r should not perform mane ma cs on cats . Improve the function so that it tries to convert any strings in the list into floating point numbers, but skips any string that cannot be converted to a number. You wl have to make use of trylexcept to catch any conversion errors that occur In [20]: def prodBetter (1): for i in 1: if type(i) in (int,float): return p In [21]: prodEvenBetter ([2, [7, 8, ]. 3, kittens']) 6 Out [21]: True In [24]: prodEvenBetter([2, [7, 8, 9], 3, '3.14']) 18.84 out [24]: False
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
