Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Albert Visser" Newsgroups: comp.lang.python Subject: Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Date: Sat, 05 Mar 2016 13:27:12 +0100 Lines: 88 Message-ID: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <4a937ead-4e40-4d20-8514-27b6145dd27f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de OsmRDSH49EV8kHUEDU91KwWcp2PLgBVQRs15RiyngsMg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'amount:': 0.07; 'constructor': 0.07; 'unittest': 0.07; 'subject:help': 0.07; 'client:': 0.09; 'subclass': 0.09; 'python': 0.10; 'accordingly.': 0.13; 'def': 0.13; 'subject: \n ': 0.15; '"error': 0.16; '"invalid': 0.16; '2016': 0.16; 'assigns': 0.16; 'bankaccount': 0.16; 'meanwhile,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'setup(self):': 0.16; 'subject:class': 0.16; 'subject:parameters': 0.16; 'transaction"': 0.16; 'withdrawal': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'subject:project': 0.18; '2015': 0.20; 'sat,': 0.23; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'skip:m 30': 0.27; '50,': 0.29; 'skip:b 40': 0.29; 'print': 0.30; 'that.': 0.30; 'transaction': 0.30; 'probably': 0.31; 'skip:_ 10': 0.32; 'december': 0.32; 'class': 0.33; 'message.': 0.33; 'running': 0.34; 'received:google.com': 0.35; 'programming.': 0.35; 'received:74.125.82': 0.35; 'should': 0.36; 'project': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; '12,': 0.37; 'skip:s 40': 0.38; 'test': 0.39; 'subject:the': 0.39; 'takes': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'called': 0.40; 'your': 0.60; 'deposit': 0.61; 'subject: ': 0.61; 'subject:Need': 0.61; 'saturday,': 0.63; 'information': 0.63; 'balance': 0.64; 'skip:a 40': 0.64; 'mar': 0.65; 'received:74.125.82.47': 0.84; 'albert': 0.91; 'examine': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:subject:references:date:mime-version:content-transfer-encoding :from:message-id:in-reply-to:user-agent; bh=XPNy6iEwHHOTYfYXbih4pr/e90MFP+yTzd8vLUizm8A=; b=OnGyMQ78EleuRGX8WFdiKkJ3i0rrDWNQQpHimBu20bHC5U8Fvg/HloZI3SSc2BJq2D TYd8QnV4Q1Trgd2pJlbKwXIik/lyMHurC3vyYk7hDO2HuWb8wuLGN/12Ul1HcJ3WWKxr YYP+pOtU8WuO66RnjdQDzaSvC8n6RSVdQBhBWZyIiB200NDffDIyCLDfeAsMnlasVESA chHJZUQYbfCW746et+1wGkpvNT9ashPKwhZYrjh4es/H9CU0aDjdv8dsfTLoJhJ23EYf Pe5uJT3LHMwNRiTNl4392godpJnNCc3vY8S9R7B5BXGGZXFy2+nRwk3QJ4ilX3gxGXOh WNLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=XPNy6iEwHHOTYfYXbih4pr/e90MFP+yTzd8vLUizm8A=; b=fimEhICrGI7mtflU5xQHR5/sQHV6NPSfQ+RSed9aXZTueqaZe3HWs0jYYofqvq2dsC bNBWugJI0+Ntcv5qe9Ij0Vo5Oa0e9UUg88HW6QIsTWl7PChZz7VG+2in/c9P062oavF0 CVV3I2rBtggJ65cfRM2jEGUbqktlhvo3mhlv0ZGW/Z2F8+9hCVnqAwIlSN/kLJnBdmbI wCtvy0IubxeSmvoajyZfnXMlC8nKy9YZKvQe7VM+Bv7rOrU3QXtw1Z8BPRAEihsLgCvR m5RAethh1ehrZ3kOf9KXKAPdiyJOcUBQpFSFr6dg/rVqkVBBXXfFH6AFaoRkOXd4kTRL kH7Q== X-Gm-Message-State: AD7BkJJgk/XialcEAsbB9W0h7tTdhWOn038vwvjFmllNVUcKLqavACoGJfxBHDWjefbZsQ== X-Received: by 10.194.61.209 with SMTP id s17mr13462046wjr.35.1457180834163; Sat, 05 Mar 2016 04:27:14 -0800 (PST) In-Reply-To: <4a937ead-4e40-4d20-8514-27b6145dd27f@googlegroups.com> User-Agent: Opera Mail/12.16 (Linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104093 On Sat, 05 Mar 2016 08:41:39 +0100, 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.. Most probably there's extra information available on the "Error running your script" message. You should examine that. Meanwhile, I think the line "return invalid transaction" provides a clue. -- Vriendelijke groeten / Kind regards, Albert Visser Using Opera's mail client: http://www.opera.com/mail/