Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Cameron Simpson Newsgroups: comp.lang.python Subject: Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Date: Mon, 28 Dec 2015 14:32:58 +1100 Lines: 38 Message-ID: References: <5e43da5b-01e8-4395-a04c-dc311844a617@googlegroups.com> Reply-To: python-list@python.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-Trace: news.uni-berlin.de WJdO7sSyyk5BZyEOz4KW9wNcuV7Mwm6xsFlT1YsWZoVA== 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; 'elif': 0.04; 'used.': 0.05; 'data):': 0.07; 'subject:help': 0.07; 'cc:addr:python-list': 0.09; '[1,': 0.09; 'happen.': 0.09; 'iterate': 0.09; 'statements': 0.09; 'sections': 0.13; 'subject: \n ': 0.15; '"d",': 0.16; '"if"': 0.16; '23,': 0.16; '_after_': 0.16; 'all?': 0.16; 'empty.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'function?': 0.16; 'iteration': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'return,': 0.16; 'simpson': 0.16; 'subject:class': 0.16; 'subject:parameters': 0.16; 'wrote:': 0.16; 'later': 0.16; 'pfxlen:0': 0.18; 'subject:project': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'cheers,': 0.22; 'cc:no real name:2**0': 0.22; 'needed.': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'function': 0.28; "skip:' 10": 0.28; 'values': 0.28; 'loop,': 0.29; 'solution,': 0.29; 'work.': 0.30; 'code': 0.30; '15,': 0.30; 'run': 0.33; 'is?': 0.33; 'case,': 0.34; 'this?': 0.34; 'next': 0.35; 'done': 0.35; 'there': 0.36; 'subject:: ': 0.37; 'there,': 0.37; 'charset:us-ascii': 0.37; 'received:localdomain': 0.38; 'several': 0.38; 'mean': 0.38; 'means': 0.39; 'why': 0.39; 'data': 0.39; 'subject:the': 0.39; 'subject:with': 0.40; 'still': 0.40; 'some': 0.40; 'your': 0.60; 'subject:Need': 0.61; 'information': 0.63; 'better.': 0.66; 'cameron': 0.66; 'god': 0.67; 'biggest': 0.67; 'header:Reply-To:1': 0.67; 'therefore': 0.67; 'finally': 0.70; 'reply-to:no real name:2**0': 0.71; 'you:': 0.79; '>def': 0.84; 'reply-to:addr:python.org': 0.84; 'bless': 0.91; 'mean.': 0.91 Content-Disposition: inline In-Reply-To: <5e43da5b-01e8-4395-a04c-dc311844a617@googlegroups.com> User-Agent: Mutt/1.5.24 (2015-08-30) 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:100922 On 27Dec2015 12:32, Prince Udoka wrote: >thanks mr cameron simpson, finally at i got the solution, God bless you: >def manipulate_data(kind, data): > if kind == 'list': > for data in [1, 2, 3, 4, 5]: > return data.reverse() > elif kind == 'set': > for data in {"a", "b", "c", "d", "e"}: > data.add("ANDELA") > data.add("TIA") > data.add("AFRICA") > return data > elif kind == 'dictionary': > for data in {"apples": 23, "oranges": 15, "mangoes": 3, "grape": 45}: > return data.key() Have you actually run this? Because it is still not right, though far better. There are several problems: The biggest issue is that "data" is a _parameter_. This means that it is information passed into the function from outside, to be used. However, in each of your "if" sections you iterate "data" over some hardwired values in a loop, and do _nothing_ with the value passed to the function. 1: why do you have hardwired values inside this function? The next is that you have "return" statements inside the loops. This means that on the _first_ iteration of the loop, the function will return, and the later loop iterations will not happen. Normal practice would be for the "return" to be outside the loop, therefore _after_ the loop has done its work. Now, also consider what such a change would mean. For the "list" case, it would mean that the code _inside_ the loop is empty. If there is no code there, why do you have a loop at all? Perhaps it is not needed. What do _you_ think the purpose of the loop is? Cheers, Cameron Simpson