def total(self): sum=0 for elem in self: sum=sum+elem return sum
class BillBatch: def __init__(self,list_of_bills): self.list_of_bills=list_of_bills def __len__(self): return len(self.list_of_bills) def total(self): sum=0 for elem in self: sum=sum+elem return sum def __getitem__(self,index): return self.list_of_bills[index] values = [10, 20, 50, 100] print("The number of Bills in the batch: ", len(values)) print(total(values))
total
BillBatch
batch = BillBatch(values) print('Total bills:', batch.total())
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)