I need to create a function that takes one iterable parameter and adds all of the objects in the list if they are an int or float. Objects that are not int or float should be skipped and a sum of int and float should be returned. I need to use loop and isinstance function. If there is an input [5.3, 2, "Book", True], return float object should equal to 7.3. So far I have:
def add_numbers_in_list(number_list):
for x in number_list:
try:
yield float(x)
except ValueError:
pass
number_list = [5.3, 2, "Book", True]
print(sum(add_numbers_in_list(number_list)))
I'm getting 8.3 as an answer.