Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

Students also viewed these Databases questions

Question

Discuss effective techniques for reducing stage fright. (L.O. 4)

Answered: 1 week ago