Need help on a project To :"Create a class called BankAccount with the following parameters "
malitician at gmail.com
malitician at gmail.com
Thu Dec 24 14:36:11 EST 2015
On Thursday, December 24, 2015 at 3:39:34 PM UTC+1, Chris Angelico wrote:
> On Fri, Dec 25, 2015 at 1:17 AM, <princeudo52 at gmail.com> wrote:
> > i am getting to believe that no one can provide a solution to this challenge, every-one here is just beating around the bush
>
> It's not a question of 'can' but 'will'. We will not provide the
> answer to your homework question. This has already been explained to
> you.
>
> ChrisA
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
in case anybody missed the question here is it
>Create a class called BankAccount
>Create a constructor that takes in an integer and assigns this to a `balance` property.
>Create a method called `deposit` that takes in cash deposit amount and updates the balance accordingly.
>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"`
>Create a subclass MinimumBalanceAccount of the BankAccount class
and there is a unittest that evaluate our code to check if we got it right ( i believe) and here it is below
import unittest
class AccountBalanceTestCases(unittest.TestCase):
def setUp(self):
self.my_account = BankAccount(90)
def test_balance(self):
self.assertEqual(self.my_account.balance, 90, msg='Account Balance Invalid')
def test_deposit(self):
self.my_account.deposit(90)
self.assertEqual(self.my_account.balance, 180, msg='Deposit method inaccurate')
def test_withdraw(self):
self.my_account.withdraw(40)
self.assertEqual(self.my_account.balance, 50, msg='Withdraw method inaccurate')
def test_invalid_operation(self):
self.assertEqual(self.my_account.withdraw(1000), "invalid transaction", msg='Invalid transaction')
def test_sub_class(self):
self.assertTrue(issubclass(MinimumBalanceAccount, BankAccount), msg='No true subclass of BankAccount')
and i come up with this code which i believe i'm 80 percent correct
class BankAccount:
def __init__(self, initial_amount):
self.balance = initial_amount
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
if self.balance>= amount:
self.balance -= amount
else:
print('invalid transaction')
a1 = BankAccount (90)
a1.deposit(90)
a1.withdraw(40)
a1.withdraw(1000)
class MinimumBalanceAccount(BankAccount):
def __init__(self):
BankAccount.__init__(self)
but i kept getting this error from the unittest
{"finished": true, "success": [{"fullName": "test_balance", "passedSpecNumber": 1}, {"fullName": "test_deposit", "passedSpecNumber": 2}, {"fullName": "test_sub_class", "passedSpecNumber": 3}, {"fullName": "test_withdraw", "passedSpecNumber": 4}], "passed": false, "started": true, "failures": [{"failedSpecNumber": 1, "fullName": "test_invalid_operation", "failedExpectations": [{"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"}}
invalid transaction
invalid transaction
its like this part of the unittest explains my error
[{"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"}}
but i dont know what it means or where i have gone wrong in my code
and for that need help on Create a subclass MinimumBalanceAccount of the BankAccount class
i believe the last three lines of my code answered your question.
i believe someone can help me with my problem.
Thanks in advance
More information about the Python-list
mailing list