Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Erik Newsgroups: comp.lang.python Subject: Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Date: Thu, 24 Dec 2015 21:09:04 +0000 Lines: 64 Message-ID: References: <5ec1d759-a2ab-4193-a4aa-869c0bf0506c@googlegroups.com> <1e0feecd-6292-406d-ac27-d32742a4023a@googlegroups.com> <8297515b-834b-4829-abb4-0191a66222bb@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de SNn/CZWMqIkgbd2EHPb8EAW5L1OmT7Tfd7cvMPO1uvTQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'paths': 0.05; 'amount:': 0.07; 'assignment': 0.07; 'seemed': 0.07; 'subject:help': 0.07; 'subclass': 0.09; 'accordingly.': 0.13; 'question.': 0.13; 'def': 0.13; 'subject: \n ': 0.15; '(when': 0.16; '23,': 0.16; 'bankaccount': 0.16; 'confusion': 0.16; 'fixing.': 0.16; 'from:addr:python': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'run.': 0.16; 'subject:class': 0.16; 'subject:parameters': 0.16; 'too).': 0.16; 'unfair': 0.16; 'withdrawal': 0.16; 'wording': 0.16; 'wrote:': 0.16; 'subject:project': 0.18; 'uses.': 0.22; 'code,': 0.23; 'bit': 0.23; 'seems': 0.23; 'errors': 0.23; 'slightly': 0.23; "haven't": 0.24; 'tried': 0.24; 'words': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'chris': 0.26; 'figure': 0.27; 'skip:m 30': 0.27; 'error': 0.27; 'question': 0.27; 'looks': 0.29; 'doing?': 0.29; 'creating': 0.30; 'code': 0.30; 'guess': 0.31; 'probably': 0.31; 'another': 0.32; 'included': 0.32; 'skip:_ 10': 0.32; 'posting': 0.32; 'related': 0.32; 'addresses': 0.32; 'received:84': 0.32; 'run': 0.33; 'class': 0.33; 'problem': 0.33; 'similar': 0.33; 'list': 0.34; 'instance': 0.35; 'asking': 0.35; 'expected': 0.35; 'problem.': 0.35; 'unit': 0.35; 'but': 0.36; 'too': 0.36; 'should': 0.36; 'lines': 0.36; 'guidance': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'method': 0.37; 'thought': 0.37; 'difference': 0.38; 'reports': 0.38; 'skip:s 40': 0.38; 'why': 0.39; 'test': 0.39; 'subject:the': 0.39; 'takes': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'called': 0.40; 'some': 0.40; 'questions': 0.40; 'your': 0.60; 'subject:Need': 0.61; 'side': 0.62; 'email addr:gmail.com': 0.62; 'charset:windows-1252': 0.62; 'spot': 0.63; 'different': 0.63; 'latest': 0.64; 'balance': 0.64; 'between': 0.65; 'believe': 0.66; 'better.': 0.66; 'said:': 0.66; 'results': 0.66; 'acts': 0.72; 'carefully': 0.72; 'attention': 0.76; 'confusing': 0.84; 'harness': 0.84; 'homework': 0.84; 'careful': 0.91; 'response,': 0.95 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=Iat6Ijea c=1 sm=1 tr=0 a=Ypmeq7T0cKALDUsRPCToMg==:117 a=Ypmeq7T0cKALDUsRPCToMg==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=N659UExz7-8A:10 a=pGLkceISAAAA:8 a=pbyq8QXOK88fsvPtWpgA:9 a=pILNOxqGKmIA:10 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.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:100831 On 24/12/15 19:36, malitician@gmail.com wrote: > you are right chris > it is a homework, but we are to figure out the solution first , all we need is some guidance please and not to be spoon fed like many thought From your response, it seems that this is a homework question that a group of you are working on. That might explain some of the confusion (both from your side, posting similar questions and slightly confusing replies) and from the list side (asking why different email addresses were being used - it all seemed a bit suspicious) ... I would recommend that one of you acts as a spokesperson for the group. However, this latest response is much better. You included your code, and it looks like it would compile (I haven't run it myself, but you've included reasonable results too). Your problem looks like it's related to how the unit test harness reports its errors and I guess it's a bit unfair for you to completely have to understand how that works if you're just learning. However, the wording of the assignment _does_ give a clue as to the problem. The error seems to be coming from the test for the "withdraw" method with a value greater that what should be the current balance: > [{"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.000080"}} Your assignment said: >> 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"` Your method is: > def withdraw(self, amount): > if self.balance>= amount: > self.balance -= amount > else: > print('invalid transaction') Can you spot the difference between what the assignment is asking for and what the method is doing? Look at both paths carefully (when called with a valid amount and when called with an amount that is too large). Pay careful attention to the words the assignment uses. > a1 = BankAccount (90) > a1.deposit(90) > a1.withdraw(40) > a1.withdraw(1000) > class MinimumBalanceAccount(BankAccount): > def __init__(self): > BankAccount.__init__(self) [snip] > i believe the last three lines of my code answered your question. When the assignment requested you create a subclass, it probably expected a subclass that would run. Have you tried creating an instance of your subclass? Try it - you might see another problem that needs fixing. E.