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

mrkimanindegwa at gmail.com mrkimanindegwa at gmail.com
Tue Jan 12 02:21:21 EST 2016


On Saturday, December 12, 2015 at 12:05:29 PM UTC+3, 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')



I would try.

class BankAccount:
    def __init__(self,balance):
        self.balance=balance
    def deposit(self):
        print("Please enter ammount to deposit")
        dep=input()
        global depbalance
        depbalance=int(self.balance)+int(dep)
        print("New balance is",depbalance)
    
    def withdraw(self):
        print("Please enter ammount to withdraw")
        withd=input()
        if int(withd) > int(depbalance):
            print("Invalid Transaction")
        else:
            withbalance= depbalance-int(withd)
            print("New balance after widthdrawal is",withbalance)
        
myAccount=BankAccount(0)
myAccount.deposit()
myAccount.withdraw()

class minimumBalanceAccount(BankAccount):
    def msg(self):
        print("This is a sub class")
        
mini=minimumBalanceAccount(0)
mini.msg()
mini.deposit()
mini.withdraw()

It may not be as fancy.
Although i dont understand the relevance of the test part in your question





More information about the Python-list mailing list