Path: csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Mark Lawrence Newsgroups: comp.lang.python Subject: Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Date: Sun, 20 Dec 2015 01:51:36 +0000 Lines: 56 Message-ID: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <8b40be10-d859-418d-b6b6-f687463a4847@googlegroups.com> <5675FFAD.3040902@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de /7cWwTB/CU4Ah3XJwfiVsAFfTk/5KAT5WvizS75M0zrw== 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; 'from:addr:yahoo.co.uk': 0.05; 'method.': 0.05; 'false,': 0.07; 'subject:help': 0.07; 'expected.': 0.09; 'logic': 0.09; 'question?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 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; 'frankly': 0.16; 'grounds': 0.16; 'guessing': 0.16; 'happily': 0.16; 'inclined': 0.16; 'outputs': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 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; 'language': 0.19; '>>>': 0.20; 'prevent': 0.20; "we'd": 0.21; 'lawrence': 0.22; 'code,': 0.23; 'wrote': 0.23; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'skip:" 20': 0.26; 'skip:m 30': 0.27; 'error': 0.27; 'question': 0.27; 'executing': 0.27; 'correct': 0.28; 'idea': 0.28; "i'm": 0.30; 'transaction': 0.30; 'code': 0.30; 'skip:[ 10': 0.31; 'probably': 0.31; 'skip:_ 10': 0.32; 'language.': 0.32; 'morning': 0.32; 'run': 0.33; 'class': 0.33; 'michael': 0.33; 'his/her': 0.33; 'running': 0.34; 'requirements': 0.35; '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; 'enough': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'mark': 0.40; 'subject:with': 0.40; 'still': 0.40; 'your': 0.60; 'provide': 0.61; 'subject:Need': 0.61; 'email addr:gmail.com': 0.62; 'charset:windows-1252': 0.62; 'day.': 0.63; 'our': 0.64; 'bothered': 0.66; 'games.': 0.84; 'presumably': 0.84; 'pythonistas,': 0.84; 'absolutely': 0.88 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 195.147.228.69 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: <5675FFAD.3040902@gmail.com> 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:100618 On 20/12/2015 01:09, Michael Torrie wrote: > 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? > Frankly I've no idea on the grounds that I simply cannot be bothered to look, and at this time of the night/early morning I'm not inclined to play guessing games. Perhaps the OP would be kind enough to provide the requirements and his/her code in one hit, the answer can be one hit, and we happily move on to Boxing day. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence