Need help on a project To :"Create a class called BankAccount with the following parameters "

Cameron Simpson cs at zip.com.au
Sat Dec 26 15:20:50 EST 2015


On 26Dec2015 03:23, princeudo52 at gmail.com <princeudo52 at gmail.com> wrote:
>this is what i finally got, i give-up, some-one, any body pls help:
>def manipulate_data(list_data, set_data):
>    if list_data == ["apples", "orange", "mangoes"]:
>        for set_data in reversed(set_data):
>            return set_data
>    elif manipulate_data(list_data == {"apples", "orange", "mangoes"}):
>        list_data.append("ANDELA", "TIA", "AFRICA")
>        for set_data in list_data:
>            return set_data
>    if manipulate_data(list_data == {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45}):
>        return dict.keys()

It is like you have not read the question at all. To remind you:

  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 ...

So clearly the function must start like this:

  def manipulate_data(kind, data):

and have some kind of decision inside the function, based on the first 
parameter, which will be one of the strings "list", "set" or "dictionary".

Instead, you have written a function above which seems to accept two parameters 
with the first being a list and the second a set.

Perhaps you have not realised that while Python has types, a variable may refer 
to an object of _any_ type. So the "data" parameter in my example above may be 
a list OR a set OR a dictionary. (Or anything else, but you only need to cope 
with those three).

So the function might be called in these ways:

  manipulate_data("list", ["apples", "orange", "mangoes"])

  manipulate_data("set", {"apples", "orange", "mangoes"})

  manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45})

In fact, I suggest you make your test program end with those three calls, so 
that it looks like this (again, untested - this is a framework for you to 
complete):

  def manipulate_data(kind, data):
    if kind == 'list':
      ... do stuff with data using it as a list ...
      ... return the reverse of a list ...
    elif kind == 'set':
      ... do stuff with data using it as a set ...
      ... add items `"ANDELA"`, `"TIA"` and `"AFRICA"` to the set ...
      ... and return the resulting set ...
    elif kind == 'dictionary':
      ... do stuff with data using it as a dictionary ...
      ... return the keys of a dictionary ...
    else:
      raise ValueError("invalid kind %r, expected 'list', 'set' or 'dictionary'" % (kind,))

  manipulate_data("list", ["apples", "orange", "mangoes"])

  manipulate_data("set", {"apples", "orange", "mangoes"})

  manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45})

so that it is a small program which defines your function and then calls it 
three times with different parameters.

Note that where your question says "a list" or "the set" or "a dictionary", it 
is really referring to the "data" parameter, so that is what you should be 
working with.

Cheers,
Cameron Simpson <cs at zip.com.au>

>https://mail.python.org/mailman/listinfo/python-list

On 26Dec2015 11:09, Cameron Simpson <cs at zip.com.au> wrote:
>On 25Dec2015 15:05, princeudo52 at gmail.com <princeudo52 at 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 at gmail.com <princeudo52 at 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 <cs at zip.com.au>
>-- 
>https://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list