'float' object has no attribute 'insert'

Question:

a = [5, -2.5, 3, 4, 12, 17]
v = []
b = 0
c = 1
for i in a:
    if i>0:
        b = b + 1
        print(i, end=" ")
    elif i<0:
        v.insert(i)
print(v.sum())

i.insert(v)
AttributeError: ‘float’ object has no attribute ‘insert’

                                .

Asked By: g0lnad

||

Answers:

you should be using the insert method when working with lists and you should specify the position.. in this case, I think you wanted to use the append method.. check more about the list methods from here

Answered By: Ghassen Jemaî