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: Sat, 26 Dec 2015 11:09:41 +1100 Lines: 70 Message-ID: References: <9b74e1e6-a28e-475d-b213-3a80e241773d@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 hsZEIcvFTO9wYYsnSyhpDgOdrEmPJQJw1GX2+oTPNZqA== 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; 'else:': 0.03; '16,': 0.03; 'elif': 0.04; 'resulting': 0.04; 'context': 0.05; 'data):': 0.07; 'differently': 0.07; 'subject:help': 0.07; 'cc:addr:python-list': 0.09; '[1,': 0.09; 'already.': 0.09; 'given,': 0.09; 'parameter.': 0.09; 'specifying': 0.09; 'python': 0.10; 'def': 0.13; 'discussions': 0.15; 'subject: \n ': 0.15; 'things.': 0.15; 'assisted': 0.16; 'bind': 0.16; 'dictionary.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'means:': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'parameter,': 0.16; 'quoted': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simpson': 0.16; 'skip:{ 40': 0.16; 'subject:class': 0.16; 'subject:parameters': 0.16; 'wrote:': 0.16; 'string': 0.17; 'pfxlen:0': 0.18; 'skip:{ 20': 0.18; 'subject:project': 0.18; 'tells': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'first,': 0.20; 'do.': 0.22; 'keys': 0.22; 'parameter': 0.22; 'cheers,': 0.22; 'pass': 0.22; 'cc:no real name:2**0': 0.22; 'decide': 0.23; 'specified': 0.23; 'this:': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'define': 0.27; 'question': 0.27; 'function': 0.28; "skip:' 10": 0.28; 'values': 0.28; 'actual': 0.28; 'dictionary': 0.29; 'raise': 0.29; 'starts': 0.29; 'code': 0.30; 'task': 0.30; 'skip:[ 10': 0.31; 'supposed': 0.31; 'post': 0.31; 'posting': 0.32; 'problem': 0.33; 'third': 0.33; 'instead,': 0.33; 'similar': 0.33; 'structure': 0.34; 'add': 0.34; 'list': 0.34; 'text': 0.35; 'question,': 0.35; 'asking': 0.35; 'expected': 0.35; 'problem.': 0.35; 'according': 0.36; 'list,': 0.36; 'should': 0.36; 'there': 0.36; 'skip:{ 10': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'charset:us-ascii': 0.37; 'starting': 0.37; 'received:localdomain': 0.38; 'skip:s 40': 0.38; 'stuff': 0.38; 'wrong': 0.38; 'data': 0.39; 'does': 0.39; 'subject:the': 0.39; 'system.': 0.39; 'subject:with': 0.40; 'some': 0.40; 'your': 0.60; 'default': 0.61; 'subject:Need': 0.61; 'email addr:gmail.com': 0.62; 'more': 0.63; 'benefit': 0.66; 'cameron': 0.66; 'reverse': 0.66; 'here': 0.66; 'header:Reply-To:1': 0.67; 'subject': 0.70; 'reply-to:no real name:2**0': 0.71; 'messaging': 0.72; 'gotten': 0.76; 'obvious': 0.76; '>def': 0.84; 'reply-to:addr:python.org': 0.84; 'examine': 0.95; 'instant': 0.98 Content-Disposition: inline In-Reply-To: <9b74e1e6-a28e-475d-b213-3a80e241773d@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:100870 On 25Dec2015 15:05, princeudo52@gmail.com wrote: >i have gotten the answer of that problem Please include some context when posting to the list; there are many discussions and it is best to include a little more than the subject line in such things. It is also polite to post your working solution for the benefit of those who have assisted you, or for others with a similar problem. Then two more messages in quick succession: this list is not an instant messaging system. Please try to post a single message, with your question and also what code you have already. Regarding your actual question, commentry below the quoted text follows... On 25Dec2015 15:08, princeudo52@gmail.com wrote: >Create a function manipulate_data that does the following >Accepts as the first parameter a string specifying the data structure to be used "list", "set" or "dictionary" >Accepts as the second parameter the data to be manipulated based on the data structure specified e.g [1, 4, 9, 16, 25] for a list data structure >Based off the first parameter > > return the reverse of a list or > add items `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set and return the resulting set > return the keys of a dictionary. > >#my solution is: >def manipulate_data(dic,dict_data = {'name':'prince','age':21,'sex':'male'}): > return dict_data.keys() > >def manipulate_data( alist, list_data = [2,8,16,23,14]): > return list_data.reverse() > >def manipulate_data(aset, set_data = {"bee","cee","dee"}): > set_data = {"bee","cee","dee"} > set_data.update("ANDELA","TIA","AFRICA") > return dictionary_data >#please what is wrong with my code The most obvious thing that is wrong it that you have 3 functions here with the same name. In Python that means: define the first function and bind it to the name "manipulate_data". Then define the second and bind it to the same name as the first, discarding the first function. The define the third and bind it to the same name again, discarding the second function. Your task is asking for a _single_ function which behaves differently according to a parameter which tells it what kind of data is has been given, so you want a function which starts like this: def manipulate_data(kind, data): and you are supposed to pass in the string "list", "set" or dictionary for the first parameter, and some corresponding list, set or dictionary as the second parameter. There should _not_ be default values for either of these. Instead, your function should examine the "kind" parameter and decide what to do. So it would reasonably look like this (untested): def manipulate_data(kind, data): if kind == 'list': ... do stuff with data using it as a list ... elif kind == 'set': ... do stuff with data using it as a set ... if kind == 'dictionary': ... do stuff with data using it as a dictionary ... else: raise ValueError("invalid kind %r, expected 'list', 'set' or 'dictionary'" % (kind,)) Try starting with that and see how you go. Cheers, Cameron Simpson