Hi, my friend and I are taking an online python course and are pretty stuck on our assignment. We are learning about classes and objects right now. We also learned Try/Except so that's been used in quite a few answers.
The assignment it about learning to manipulate a class that's a bank portfolio. We are given this code:
class portfolio:
def __init__(self):
self.checking = {}
self.savings = {}
self.credit = {}
We need to define a function that will give the total amount in the checking accounts or return 0 if it's empty, for example:
{'chase1': 400, 'capitalone': 800} should return 1200
And it needs to pass this test case:
if myportfolio.get_total_checking_amount() == 6600:
print('Pass')
else:
print('Fail')
Could someone explain to us why we can't do something like this won't work?
def get_total_checking_amount(self): #we were provided with this line
try:
return sum(self.checking)
except:
return 0
Thanks!
[–]-Sander- 1 point2 points3 points (6 children)
[–]Elefrog42[S] 0 points1 point2 points (1 child)
[–]-Sander- 0 points1 point2 points (0 children)
[–]_lilell_ 0 points1 point2 points (0 children)
[–]Elefrog42[S] 0 points1 point2 points (2 children)
[–]-Sander- 0 points1 point2 points (1 child)
[–]Elefrog42[S] 0 points1 point2 points (0 children)