Need help on a project To :"Create a class called BankAccount with the following parameters "

Peter Otten __peter__ at web.de
Sat Mar 5 04:07:28 EST 2016


lucasfrank254 at gmail.com wrote:

> On Saturday, December 12, 2015 at 1:05:29 AM UTC-8, Harbey Leke wrote:
>> 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
>> 
>> Please i need help on this i am a beginer into python programming.
>> 
>> 
>> Also below is a test case given for this project
>> 
>> 
>> 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')
> 
> my solution is:
> 
> class BankAccount(object):
>     def __init__(self, initial_balance):
>         self.balance = initial_balance
>     def deposit(self, amount):
>         self.balance +=amount
>     def withdraw(self, amount):
>           if self.balance>= amount:
>               self.balance  -=  amount
>           else:
>             return invalid transaction
> a1 = BankAccount (90)
> a1.deposit(90)
> a1.withdraw(40)
> a1.withdraw(1000)
> class MinimumBalanceAccount(BankAccount):
>   def __init__(self):
>     BankAccount.__init__(self,minimum_balance)
>     self.minimum_balance = minimum_balance
>     my_account = BankAccount(90)
>     my_account.withdraw(40)
>     print my_account.balance
> 
> 
> It keeps alerting me that,"Error running your script".Where might I have
> gone wrong?Please help..

When you run the above code as a script on your own machine, i. e. if the 
file is called bank.py you type

python3 bank.py

on the commandline (if you are using Idle, you can hit F5 instead), what 
happens?

The output should give you a hint about what's wrong and where in the script 
the problem occurs. This output is called "traceback", and if you cannot 
make sense of it, come back here to ask, but don't forget to include the 
traceback into your post. Don't paraphrase, use cut and paste.




More information about the Python-list mailing list