Re: Need help on a project To :"Create a class called BankAccount with the following parameters "
good explanation Steven but can you please do more by posting the exact code as it relate to the question please? -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help on a project To :"Create a class called BankAccount with the following parameters "
you are absolutely correct Mark
i'm a beginner in python and from the original question and test case given
above i wrote this
class BankAccount(object):
def __init__(self, initial_balance=0):
self.balance = initial_balance
def deposit(self, amount):
self.balance +=amount
def withdraw(self, amount):
self.balance -= amount
my_account = BankAccount(90)
my_account.withdraw(1000)
if my_account.balance < 4:
print('invalid transaction')
class MinimumBalanceAccount(BankAccount):
def __init__(self, MinimumBalance=4):
self.minbalance = MinimumBalance
after executing this i got this TEST SOLUTION ERROR which i don't know what it
means
{"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\nself.assertEqual(self.my_account.withdraw(1000),
\"invalid transaction\", msg='Invalid transaction')\nAssertionError: Invalid
transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, "time":
"0.65"}}
-910
invalid transaction
SO please what is wrong with my code, does it not meet the requirement of the
"test case" given above in the question?
Thanks in advance
--
https://mail.python.org/mailman/listinfo/python-list
Re: Need help on a project To :"Create a class called BankAccount with the following parameters "
On Thursday, December 24, 2015 at 3:39:34 PM UTC+1, Chris Angelico wrote:
> On Fri, Dec 25, 2015 at 1:17 AM, 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\nself.assertEqual(self.my_account.withdraw(1000),
\"invalid transaction\", msg='Invalid transaction')\nAssertionError: Invalid
transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, "time":
"0.80"}}
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.80"}}
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
--
https://mail.python.org/mailman/listinfo/python-list
Re: Need help on a project To :"Create a class called BankAccount with the following parameters "
On Saturday, December 26, 2015 at 3:04:45 AM UTC+1, [email protected] wrote: > #i have worked over 2hours only to get this: some-one help please > manipulate_data = [] > item = {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45} > manipulate_data.append(item) > for i in reversed(manipulate_data): > new = {"ANDELA", "TIA", "AFRICA"} > def list_append(manipulate_data, new): > manipulate_data.append(new) > return new > return dict.keys() > > > print manipulate_data > #this is the instruction: > Create a function manipulate_data that does the following > Accepts as the first parameter a string specifying the data structure to be > used "list", "set" or "dictionary" > Accepts as the second parameter the data to be manipulated based on the data > structure specified e.g [1, 4, 9, 16, 25] for a list data structure > Based off the first parameter > > return the reverse of a list or > add items `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set and return the > resulting set > return the keys of a dictionary. I am now more confused than before, as beginners like we have stated earlier, how does this solution applies to the real question ( bank account ) -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help on a project To :"Create a class called BankAccount with the following parameters "
On Thursday, December 24, 2015 at 9:58:54 PM UTC+1, Tim Chase wrote: > On 2015-12-24 11:36, [email protected] wrote: > > 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 > > Ah, with the intended interface as given by the tests, and the code > you've already put together, you'll find comp.lang.python is a much > friendlier place. > > > > def test_invalid_operation(self): > > self.assertEqual(self.my_account.withdraw(1000), "invalid > > transaction", msg='Invalid transaction') > > The test above is failing because your withdraw() method doesn't > return "invalid transaction" but rather prints it: > > > def withdraw(self, amount): > > if self.balance>= amount: > > self.balance -= amount > > else: > > print('invalid transaction') > > as gleaned from this error message: > > > [{"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.80"}} > > The test says "I expected that calling the function would return > "invalid transaction" but it didn't" (a better test-runner would > also have let you know that it had returned None) > > Though frankly, I'd consider that a bad test, since it's an > exceptional condition, so it should be checking that a custom > InvalidTransactionException was raised. But sometimes you have to > work with what you've got. > > -tkc you and others here saved my days , instead of "RETURN" i have been using "PRINT". i never knew the differences earlier . Problem solved , thanks for having guys like all of you here. I'm just a week old into python programming and i have learned a lot .Merry xmas -- https://mail.python.org/mailman/listinfo/python-list
