Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Prince Udoka 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 23:35:15 +0100 Lines: 70 Message-ID: References: <57a7133b-8ee0-4196-b2e5-6aa393a4e5fb@googlegroups.com> <20151228222953.GA94789@cskk.homeip.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de pT3CoQkIYvJFZpBcOVKimAJNM6Uq8bPAfK1WBx1/OYXw== 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; 'python,': 0.02; 'elif': 0.04; 'modify': 0.04; 'resulting': 0.04; 'modified': 0.05; 'remind': 0.05; 'caller': 0.07; 'data):': 0.07; 'subject:help': 0.07; 'ambiguity': 0.09; 'def': 0.13; 'everyone,': 0.15; 'explicitly': 0.15; 'subject: \n ': 0.15; '"d",': 0.16; '(good)': 0.16; '23,': 0.16; 'attempt.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'set,': 0.16; 'simpson': 0.16; 'subject:class': 0.16; 'subject:parameters': 0.16; 'task.': 0.16; '\xc2\xa0if': 0.16; 'wrote:': 0.16; 'skip:` 10': 0.18; 'skip:` 20': 0.18; 'skip:{ 20': 0.18; 'subject:project': 0.18; '(in': 0.18; 'email addr:gmail.com>': 0.18; 'language': 0.19; '2015': 0.20; 'not,': 0.22; 'cheers,': 0.22; 'code,': 0.23; 'fit': 0.23; 'dec': 0.23; 'sets': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'external': 0.27; 'skip:m 30': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; "skip:' 10": 0.28; 'values': 0.28; 'modified,': 0.29; 'question:': 0.29; 'solution,': 0.29; 'code:': 0.29; 'code': 0.30; '15,': 0.30; 'convention': 0.30; 'task': 0.30; 'supposed': 0.31; 'probably': 0.31; 'fixed': 0.31; 'says': 0.32; 'useful': 0.33; 'problem': 0.33; 'common': 0.33; 'usually': 0.33; 'previous': 0.34; 'running': 0.34; 'add': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'so,': 0.35; 'attempt': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'skip:{ 10': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'thanks': 0.37; '(with': 0.38; 'received:209': 0.38; 'thank': 0.38; 'data': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'some': 0.40; 'your': 0.60; 'subject:Need': 0.61; 'back': 0.62; 'more': 0.63; 'cameron': 0.66; 'god': 0.67; 'skip:\xc2 10': 0.67; 'calls,': 0.84; 'construct': 0.84; 'function)': 0.84; 'original.': 0.84; 'tough,': 0.84; 'imagine': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=fQyJsDHxBKxYyx5lSVugExu/0v3q2Pb26qha08LV+oA=; b=VNzV/o74juLAOclhg+nZaM2QCsbE1fk5I2U0PPMXweVRCsedrVT2HcdlnPbOWUcuWi F/9eK/IWRJjGonEXT5NWmcw2zrZMTfdIp/YhrZX2MygSGHI/PotMaFlZjhYiRkgqg24V aEwzN9o+bo2q+GQv0vLp2G9zlDjhExc2R6Z2T5yQV8McL82q1JwCzfUWj3kk8A5nt7r8 CVgwtEnzcmVmPXXiUrKGQyfnTl78Yhxap2678u+Aa1bHSotuphUIj7d7yjQEwnVjGAS0 e45EPOOopiL9NPKoQd7/yi4Ou9ii5w3KvloY6fxyZokQteBiJYVSjcXrwODtUaleA4sd t5Cg== X-Received: by 10.25.156.198 with SMTP id f189mr2727081lfe.70.1451342115388; Mon, 28 Dec 2015 14:35:15 -0800 (PST) In-Reply-To: <20151228222953.GA94789@cskk.homeip.net> X-Mailman-Approved-At: Mon, 28 Dec 2015 17:39:39 -0500 X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ 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:100940 thanks everyone, though it was very tough, but i thank GOD On Mon, Dec 28, 2015 at 11:29 PM, Cameron Simpson wrote: > On 28Dec2015 01:34, Prince Udoka wrote: > >> bu i have come up with a solution, that will work but encounter a problem >> in the set, giving set not manipulated correctly: >> >> def manipulate_data(kind, data): >> if kind == 'list': >> return list(data)[::-1] >> elif kind == 'set': >> return set(data) >> elif kind == 'dictionary': >> return dict.keys(data) >> manipulate_data("list", range(1,6)) >> manipulate_data("set", {"a", "b", "c", "d", "e", "ANDELA", "TIA", >> "AFRICA"}) >> manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, >> "grapes": 45}) >> >> the thing now is the function to use in adding "ANDELA", "TIA", "AFRICA" >> pls 4give my use of language >> > > You are very close. Let me remind you of the original task text: > > add items `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set and return the > resulting set > > Your previous attempt (with hardwired values inside the function) actually > had code to do it. > > While you have pulled out all the hardwired values from the function > (good) and put them in the external calls, note that the task explicitly > says "add items `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set". So _those_ > values _are_ supposed to be hardwired inside the function - they are a > fixed part of the task. So move them back in, as in your previous attempt. > > There is some ambiguity in that part of the question: should you return a > _new_ set consistint of the original set plus the three new values, or > simply add the three values to the original set? Your prior code modified > the original set, which may fit the task specification. > > However, it is a common design objective that functions do not, > _normally_, modify their arguments. So, consider this code: > > set1 = {"a", "b", "c", "d", "e"} > set2 = manipulate_data("set", set1) > > After running this, set2 should look like this: > > {"a", "b", "c", "d", "e", "ANDELA", "TIA", "AFRICA"} > > (in some order -- sets are not ordered). However, what about set1? In your > current code, set1 is modified, so it will be the same. But you can imagine > that it would be more useful for the caller if set1 were unchanged. > > In python, the convention is usually that if a function returns the new > value then it should not modify the original. So you should probably > construct a copy of the original set and modify that: > > data = set(data) > ... add the new values ... > return data > > Cheers, > Cameron Simpson >