Create a class called Box that has a single field property i
Create a class called Box that has a single field (property) in it called data (which will be a number). Next, create a function called box Sum that takes a list of boxes as input. The function should add up all the data in all the boxes and returns this sum.
Solution
def boxSum(num):
count=0; ## initialising count var to zero
length = len(num)## getting list length
for num in range(length):## adding every number in list to count
count=count+num;## adding
return count## returning count
class Box:
data={1,2,3,4,5}
## create the list of boxes
boxes = [Box() for i in range(6)]
## go through the list and give each box a data value
for b in range(5):
boxes[b].data=b+1
print(boxSum(boxes))
