0
How to get the total age in this list of objects?
My attempt to get the total age is at the end of the code. https://code.sololearn.com/crXq08NGPa2F/?ref=app
8 Réponses
+ 2
https://code.sololearn.com/c9uxZ3vXHCa8/?ref=app
+ 3
print(sum([i.age for i in personList ]))
+ 1
You can do it with the __add__ i believe
0
Seems the loop doesn't break
0
You have int object not iterable
0
for i in personList :
q+=i.age
print (q)
0
Ion Kare so we cant iterate throught objects at all?
0
Or was it because the object was an int?