On 24/12/15 19:36, malitic...@gmail.com wrote:
you are right chris
it is a homework, but we are to figure out the solution first , all we need is
some guidance please and not to be spoon fed like many thought
From your response, it seems that this is a homework question that a
group of you are working on. That might explain some of the confusion
(both from your side, posting similar questions and slightly confusing
replies) and from the list side (asking why different email addresses
were being used - it all seemed a bit suspicious) ...
I would recommend that one of you acts as a spokesperson for the group.
However, this latest response is much better. You included your code,
and it looks like it would compile (I haven't run it myself, but you've
included reasonable results too).
Your problem looks like it's related to how the unit test harness
reports its errors and I guess it's a bit unfair for you to completely
have to understand how that works if you're just learning. However, the
wording of the assignment _does_ give a clue as to the problem.
The error seems to be coming from the test for the "withdraw" method
with a value greater that what should be the current balance:
> [{"message": "Failure in line 23, in test_invalid_operation\n
self.assertEqual(self.my_account.withdraw(1000), \"invalid
transaction\", msg='Invalid transaction')\nAssertionError: Invalid
transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, "time":
"0.000080"}}
Your assignment said:
Create a method called `withdraw` that takes in cash withdrawal amount and updates the
balance accordingly. if amount is greater than balance return `"invalid
transaction"`
Your method is:
def withdraw(self, amount):
if self.balance>= amount:
self.balance -= amount
else:
print('invalid transaction')
Can you spot the difference between what the assignment is asking for
and what the method is doing? Look at both paths carefully (when called
with a valid amount and when called with an amount that is too large).
Pay careful attention to the words the assignment uses.
a1 = BankAccount (90)
a1.deposit(90)
a1.withdraw(40)
a1.withdraw(1000)
class MinimumBalanceAccount(BankAccount):
def __init__(self):
BankAccount.__init__(self)
[snip]
i believe the last three lines of my code answered your question.
When the assignment requested you create a subclass, it probably
expected a subclass that would run. Have you tried creating an instance
of your subclass? Try it - you might see another problem that needs fixing.
E.
--
https://mail.python.org/mailman/listinfo/python-list