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

27th Feb 2022, 6:31 PM
Lenoname
8 Answers
+ 2
https://code.sololearn.com/c9uxZ3vXHCa8/?ref=app
27th Feb 2022, 7:31 PM
Ion Kare
Ion Kare - avatar
+ 3
print(sum([i.age for i in personList ]))
28th Feb 2022, 4:30 AM
Oma Falk
Oma Falk - avatar
+ 1
You can do it with the __add__ i believe
27th Feb 2022, 7:43 PM
Ion Kare
Ion Kare - avatar
0
Seems the loop doesn't break
27th Feb 2022, 7:00 PM
Ion Kare
Ion Kare - avatar
0
You have int object not iterable
27th Feb 2022, 7:03 PM
Ion Kare
Ion Kare - avatar
0
for i in personList : q+=i.age print (q)
27th Feb 2022, 7:11 PM
Robert BƂaszczyk
Robert BƂaszczyk - avatar
0
Ion Kare so we cant iterate throught objects at all?
27th Feb 2022, 7:42 PM
Lenoname
0
Or was it because the object was an int?
27th Feb 2022, 7:42 PM
Lenoname