Commit e5951e5e authored by Samarth Joshi's avatar Samarth Joshi

Bug Fixes q6

parent 508dd088
from functools import total_ordering
@total_ordering
class BlackMoneyHolder:
def __init__(self,name,accounts_info):
self.name=name
......@@ -13,7 +14,7 @@ class BlackMoneyHolder:
return len(self.accounts_info)
def __getitem__(self, item):
return self.accounts_info[item]
return list(self.accounts_info.items())[item]
def __eq__(self, other):
return self.total_black_money()==other.total_black_money()
......@@ -21,22 +22,18 @@ class BlackMoneyHolder:
def __lt__(self, other):
return self.total_black_money() < other.total_black_money()
def __gt__(self, other):
return self.total_black_money() > other.total_black_money()
def __str__(self):
for i in self.accounts_info:
print( "%s: %s" %(i,self.accounts_info[i]))
return ''
return "\n".join([key+": "+str(value) for key, value in accounts_info.items()])
def update_amount(self,name,amount):
self.accounts_info[name]=amount
def total_black_money(self):
total_money=0
for i in accounts_info:
total_money+=self.accounts_info.get(i)
for i in self.accounts_info:
total_money = total_money + self.accounts_info.get(i)
return total_money
name="Gonia Sandhi"
accounts_info={
"Random Bank": 1000,
......@@ -44,16 +41,27 @@ accounts_info={
"Lena Bank":2000,
}
b1=BlackMoneyHolder(name,accounts_info)
print(b1)
print(b1.total_black_money())
b1.update_amount("Blood Bank",2500)
print(b1.total_black_money())
name="Champak Lal"
accounts_info={
for account in b1:
print(account)
name2="Champak Lal"
accounts_info2={
"Random Bank": 2000,
"Dena Bank":7000,
"Lena Bank":9000,
}
b2=BlackMoneyHolder(name,accounts_info)
b2=BlackMoneyHolder(name2,accounts_info2)
print(b2)
print(b2.total_black_money())
print(b1==b2,b1>b2,b1<b2)
print(b1)
print(b1)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment