On 27Dec2015 12:32, Prince Udoka <princeud...@gmail.com> 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 <c...@zip.com.au>
--
https://mail.python.org/mailman/listinfo/python-list