Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Torrie Newsgroups: comp.lang.python Subject: Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Date: Sat, 19 Dec 2015 18:09:01 -0700 Lines: 42 Message-ID: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <8b40be10-d859-418d-b6b6-f687463a4847@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de SjqvQd8g/XxSUsJ+6KeY2Q6NVizrizCqgBmBsioniR+Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'skip:[ 20': 0.03; 'true,': 0.04; 'method.': 0.05; 'false,': 0.07; 'subject:help': 0.07; 'expected.': 0.09; 'logic': 0.09; 'question?': 0.09; 'advance': 0.10; 'python': 0.10; 'output': 0.13; 'def': 0.13; 'subject: \n ': 0.15; '"invalid': 0.16; '"test': 0.16; '23,': 0.16; 'code?': 0.16; 'expect,': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'outputs': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:class': 0.16; 'subject:parameters': 0.16; 'wrote:': 0.16; 'beginner': 0.18; 'subject:project': 0.18; 'prevent': 0.20; "we'd": 0.21; 'lawrence': 0.22; 'code,': 0.23; 'wrote': 0.23; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'skip:m 30': 0.27; 'error': 0.27; 'question': 0.27; 'executing': 0.27; 'correct': 0.28; "i'm": 0.30; 'transaction': 0.30; 'code': 0.30; 'skip:[ 10': 0.31; 'probably': 0.31; 'skip:_ 10': 0.32; 'run': 0.33; 'class': 0.33; 'message-id:@gmail.com': 0.34; 'running': 0.34; 'but': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'requirement': 0.37; 'things': 0.38; 'skip:s 40': 0.38; 'wrong': 0.38; 'means': 0.39; 'test': 0.39; 'whatever': 0.39; 'does': 0.39; 'subject:the': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'mark': 0.40; 'subject:with': 0.40; 'still': 0.40; 'your': 0.60; 'subject:Need': 0.61; 'email addr:gmail.com': 0.62; 'charset:windows-1252': 0.62; 'presumably': 0.84; 'absolutely': 0.88 X-Virus-Scanned: amavisd-new at torriefamily.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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:100617 On 12/19/2015 05:41 PM, Mark Lawrence wrote: > On 19/12/2015 23:19, malitician@gmail.com wrote: >> 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') ^^^^^^^^^^^^^^^^^^ This code probably belongs in the withdraw() method. >> 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\n self.assertEqual(self.my_account.withdraw(1000), \"invalid transaction\", msg='Invalid transaction')\nAssertionError: Invalid transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, "time": "0.000065"}} >> -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 >> > > It's a start but you've still left things out. If I run your code as > given above it outputs "invalid transaction", exactly as expected. So > how are you running the code? Where does the extra output you give > above come from, presumably the "test case", whatever that might be? While the output is as we'd expect, the program's logic is probably wrong. Would not you want to put that logic in the withdraw method to prevent an invalid transaction?