Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100324 > unrolled thread
| Started by | Harbey Leke <idowuolawale@gmail.com> |
|---|---|
| First post | 2015-12-12 01:05 -0800 |
| Last post | 2016-03-05 13:27 +0100 |
| Articles | 20 on this page of 109 — 43 participants |
Back to article view | Back to comp.lang.python
Need help on a project To :"Create a class called BankAccount with the following parameters " Harbey Leke <idowuolawale@gmail.com> - 2015-12-12 01:05 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Chris Angelico <rosuav@gmail.com> - 2015-12-12 20:21 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Harbey Leke <idowuolawale@gmail.com> - 2015-12-12 02:09 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Chris Angelico <rosuav@gmail.com> - 2015-12-12 21:17 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Harbey Leke <idowuolawale@gmail.com> - 2015-12-12 02:27 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Harbey Leke <idowuolawale@gmail.com> - 2015-12-12 02:29 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Chris Warrick <kwpolska@gmail.com> - 2015-12-12 11:37 +0100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Steven D'Aprano <steve@pearwood.info> - 2015-12-12 23:32 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " mkatietola@gmail.com - 2015-12-12 09:37 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " malitician@gmail.com - 2015-12-18 19:15 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-19 14:47 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " malitician@gmail.com - 2015-12-19 15:19 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-20 00:41 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Michael Torrie <torriem@gmail.com> - 2015-12-19 18:09 -0700
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-25 15:08 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-25 15:09 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Erik <python@lucidity.plus.com> - 2015-12-26 00:01 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Cameron Simpson <cs@zip.com.au> - 2015-12-26 11:09 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-25 18:04 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Larry Hudson <orgnut@yahoo.com> - 2015-12-25 20:02 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " malitician@gmail.com - 2015-12-26 00:47 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-25 18:36 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-26 02:38 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-26 03:23 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Cameron Simpson <cs@zip.com.au> - 2015-12-27 07:20 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " lee <malitician@gmail.com> - 2015-12-27 07:02 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Erik <python@lucidity.plus.com> - 2015-12-27 15:26 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " lee <malitician@gmail.com> - 2015-12-27 12:26 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Prince Udoka <princeudo52@gmail.com> - 2015-12-27 12:32 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " lee <malitician@gmail.com> - 2015-12-27 12:54 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Erik <python@lucidity.plus.com> - 2015-12-27 21:42 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Cameron Simpson <cs@zip.com.au> - 2015-12-28 14:32 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-20 01:51 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " anyanwuchukwuemeka9@gmail.com - 2016-03-19 14:40 -0700
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Joel Goldstick <joel.goldstick@gmail.com> - 2016-03-19 18:03 -0400
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-19 22:24 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Ben Finney <ben+python@benfinney.id.au> - 2016-03-20 11:26 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Denis McMahon <denismfmcmahon@gmail.com> - 2015-12-20 11:04 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Chris Angelico <rosuav@gmail.com> - 2015-12-20 22:29 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " jeanbigboute@gmail.com - 2015-12-25 20:15 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-26 01:52 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-24 04:39 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-12-24 11:57 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-24 04:59 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Chris Angelico <rosuav@gmail.com> - 2015-12-25 00:10 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-24 06:17 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Chris Angelico <rosuav@gmail.com> - 2015-12-25 01:39 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " malitician@gmail.com - 2015-12-24 11:36 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Tim Chase <python.list@tim.thechases.com> - 2015-12-24 14:48 -0600
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " malitician@gmail.com - 2015-12-26 01:01 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Erik <python@lucidity.plus.com> - 2015-12-24 21:09 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Joel Goldstick <joel.goldstick@gmail.com> - 2015-12-24 10:47 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " "D'Arcy J.M. Cain" <darcy@VybeNetworks.com> - 2015-12-24 11:14 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Grant Edwards <invalid@invalid.invalid> - 2015-12-24 17:30 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Gene Heskett <gheskett@wdtv.com> - 2015-12-24 13:51 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " "D'Arcy J.M. Cain" <darcy@VybeNetworks.com> - 2015-12-24 14:09 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-12-24 18:55 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-12-26 11:36 +1300
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Grant Edwards <invalid@invalid.invalid> - 2015-12-31 16:46 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Chris Angelico <rosuav@gmail.com> - 2015-12-25 03:31 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " princeudo52@gmail.com - 2015-12-25 15:05 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " xaviertim017@gmail.com - 2016-01-01 15:15 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " lee <malitician@gmail.com> - 2015-12-28 01:25 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Prince Udoka <princeudo52@gmail.com> - 2015-12-28 01:29 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Prince Udoka <princeudo52@gmail.com> - 2015-12-28 01:39 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " homiemusa@gmail.com - 2016-01-11 13:22 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Prince Udoka <princeudo52@gmail.com> - 2015-12-28 01:34 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Ben Finney <ben+python@benfinney.id.au> - 2015-12-28 20:41 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Cameron Simpson <cs@zip.com.au> - 2015-12-29 09:29 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " lee <malitician@gmail.com> - 2015-12-29 00:49 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Cameron Simpson <cs@zip.com.au> - 2015-12-29 21:48 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " lee <malitician@gmail.com> - 2015-12-29 04:39 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " homiemusa@gmail.com - 2016-01-11 14:07 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-01-11 19:46 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Prince Udoka <princeudo52@gmail.com> - 2015-12-28 23:35 +0100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " phatsammhiel@gmail.com - 2016-01-13 05:27 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Ben Finney <ben+python@benfinney.id.au> - 2015-12-28 20:38 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " lee <malitician@gmail.com> - 2015-12-28 01:53 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Joel Goldstick <joel.goldstick@gmail.com> - 2015-12-28 07:32 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " botic <princeudo52@gmail.com> - 2015-12-28 14:10 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " phatsammhiel@gmail.com - 2016-01-13 05:28 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Chris Angelico <rosuav@gmail.com> - 2016-01-14 00:37 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Joel Goldstick <joel.goldstick@gmail.com> - 2016-01-13 09:43 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Tim Golden <mail@timgolden.me.uk> - 2016-01-13 15:23 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Andrew Ongko <andrew.ongko@gmail.com> - 2016-01-13 22:35 +0700
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " phatsammhiel@gmail.com - 2016-01-13 05:44 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " kasale.jacktone@gmail.com - 2016-01-14 03:50 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-28 14:27 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Won Chang <princeudo52@gmail.com> - 2015-12-30 10:21 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Joel Goldstick <joel.goldstick@gmail.com> - 2015-12-30 15:06 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Joel Goldstick <joel.goldstick@gmail.com> - 2015-12-30 15:11 -0500
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " acushla4real@gmail.com - 2016-01-08 08:37 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " ifeanyioprah@gmail.com - 2016-01-11 21:26 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " ifeanyioprah@gmail.com - 2016-01-11 21:30 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " ifeanyioprah@gmail.com - 2016-01-11 21:33 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " ifeanyioprah@gmail.com - 2016-01-11 21:33 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " chetam.chetzy@gmail.com - 2016-03-13 17:17 -0700
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Chris Angelico <rosuav@gmail.com> - 2016-03-14 11:40 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " MRAB <python@mrabarnett.plus.com> - 2016-03-14 00:57 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Chris Angelico <rosuav@gmail.com> - 2016-03-14 12:02 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Ben Finney <ben+python@benfinney.id.au> - 2016-03-14 12:08 +1100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " BartC <bc@freeuk.com> - 2016-03-14 01:33 +0000
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " xaviertim017@gmail.com - 2016-01-01 16:24 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " mrkimanindegwa@gmail.com - 2016-01-11 23:21 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " lee <malitician@gmail.com> - 2016-01-12 05:20 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " bonfaceo3@gmail.com - 2016-01-13 03:14 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " lucasfrank254@gmail.com - 2016-03-04 23:41 -0800
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " Peter Otten <__peter__@web.de> - 2016-03-05 10:07 +0100
Re: Need help on a project To :"Create a class called BankAccount with the following parameters " "Albert Visser" <albert.visser@gmail.com> - 2016-03-05 13:27 +0100
Page 2 of 6 — ← Prev page 1 [2] 3 4 5 6 Next page →
| From | malitician@gmail.com |
|---|---|
| Date | 2015-12-26 00:47 -0800 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <e4d8b001-b1f5-40cf-b023-5fb3b82e56a9@googlegroups.com> |
| In reply to | #100874 |
On Saturday, December 26, 2015 at 3:04:45 AM UTC+1, princ...@gmail.com wrote:
> #i have worked over 2hours only to get this: some-one help please
> manipulate_data = []
> item = {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45}
> manipulate_data.append(item)
> for i in reversed(manipulate_data):
> new = {"ANDELA", "TIA", "AFRICA"}
> def list_append(manipulate_data, new):
> manipulate_data.append(new)
> return new
> return dict.keys()
>
>
> print manipulate_data
> #this is the instruction:
> 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.
I am now more confused than before, as beginners like we have stated
earlier, how does this solution applies to the real question ( bank
account )
[toc] | [prev] | [next] | [standalone]
| From | princeudo52@gmail.com |
|---|---|
| Date | 2015-12-25 18:36 -0800 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <2f7b56f9-e7c6-4433-b8c6-3589f3bd73dd@googlegroups.com> |
| In reply to | #100870 |
thank you God bless you moore...
[toc] | [prev] | [next] | [standalone]
| From | princeudo52@gmail.com |
|---|---|
| Date | 2015-12-26 02:38 -0800 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <f5c4937b-1d8f-4c28-8bdc-6c0bd5f1944d@googlegroups.com> |
| In reply to | #100870 |
@ cameron, are u sure this solution u gave me works
here is what i am getting, i am really having headache, some-one should please have mercy:
def manipulate_data(list_data, set_data):
if list_data == ["apples", "orange", "mangoes"]:
for i in reversed(set_data):
return i
elif list_data == {}
and this is the erro:
File "python", line 5
elif list_data == {}
^
SyntaxError: invalid syntax
[toc] | [prev] | [next] | [standalone]
| From | princeudo52@gmail.com |
|---|---|
| Date | 2015-12-26 03:23 -0800 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <4dba6e6d-68f5-42af-b9d8-8bb1bd92312b@googlegroups.com> |
| In reply to | #100888 |
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()
[toc] | [prev] | [next] | [standalone]
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Date | 2015-12-27 07:20 +1100 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <mailman.23.1451161263.11925.python-list@python.org> |
| In reply to | #100889 |
On 26Dec2015 03:23, princeudo52@gmail.com <princeudo52@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@zip.com.au>
>https://mail.python.org/mailman/listinfo/python-list
On 26Dec2015 11:09, Cameron Simpson <cs@zip.com.au> wrote:
>On 25Dec2015 15:05, princeudo52@gmail.com <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 <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 <cs@zip.com.au>
>--
>https://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | lee <malitician@gmail.com> |
|---|---|
| Date | 2015-12-27 07:02 -0800 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <6890848e-bffa-4cac-8a3b-3f8a529b7cd9@googlegroups.com> |
| In reply to | #100897 |
> >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@zip.com.au>
> >--
> >https://mail.python.org/mailman/listinfo/python-list
the question again
>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.
unittest for the question
>import unittest
>class DataStructureTest(TestCase):
> def setUp(self):
> self.list_data = [1,2,3,4,5]
> self.set_data = {"a", "b", "c", "d", "e"}
> self.dictionary_data = {"apples": 23, "oranges": 15, "mangoes": 3, >"grapes": 45}
>
> def test_manipulate_list(self):
> result = manipulate_data("list", self.list_data)
> self.assertEqual(result, [5,4,3,2,1], msg = "List not manipulated >correctly")
>
> def test_manipulate_set(self):
> result = manipulate_data("set", self.set_data)
> self.assertEqual(result, {"a", "b", "c", "d", "e", "ANDELA", "TIA", >"AFRICA"}, msg = "Set not manipulated correctly")
>
> def test_manipulate_dictionary(self):
> result = manipulate_data("dictionary", self.dictionary_data)
> self.assertEqual(result, ["grapes", "mangoes", "apples", "oranges"], msg = >"Dictionary not manipulated correctly")
the code i have tested base on Cameron's code
def manipulate_data(kind, data):
if kind == 'list':
return list(data)[::-1]
elif kind == 'set':
return set(data)
elif kind == 'dictionary':
return dict( data)
manipulate_data("list", range(1,6))
a = manipulate_data("set", {"a", "b", "c", "d", "e"})
a.add("ANDELA")
a.add("TIA")
a.add("AFRICA")
b = manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45})
list(b.keys())
this is the result i got from the unittest
Total Specs: 3 Total Failures: 2
1 . test_manipulate_dictionary
Failure in line 23, in test_manipulate_dictionary self.assertEqual(result, ["grapes", "mangoes", "apples", "oranges"], msg = "Dictionary not manipulated correctly") AssertionError: Dictionary not manipulated correctly
2 . test_manipulate_set
Failure in line 19, in test_manipulate_set self.assertEqual(result, {"a", "b", "c", "d", "e", "ANDELA", "TIA", "AFRICA"}, msg = "Set not manipulated correctly") AssertionError: Set not manipulated correctly
i guess i passed the first requirement to return the reversed order of the list and believe i messed up when creating a set then add data to the set, also something is wrong with returning the keys of the dictionary
can someone point out the error in my code and the meaning of the unittes error?
thanks in advance
[toc] | [prev] | [next] | [standalone]
| From | Erik <python@lucidity.plus.com> |
|---|---|
| Date | 2015-12-27 15:26 +0000 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <mailman.28.1451230013.11925.python-list@python.org> |
| In reply to | #100904 |
On 27/12/15 15:02, lee wrote:
> the code i have tested base on Cameron's code
>
> def manipulate_data(kind, data):
> if kind == 'list':
> return list(data)[::-1]
>
> elif kind == 'set':
> return set(data)
> elif kind == 'dictionary':
> return dict( data)
>
> manipulate_data("list", range(1,6))
> a = manipulate_data("set", {"a", "b", "c", "d", "e"})
> a.add("ANDELA")
> a.add("TIA")
> a.add("AFRICA")
> b = manipulate_data("dictionary", {"apples": 23, "oranges": 15, "mangoes": 3, "grapes": 45})
> list(b.keys())
[snip]
> i guess i passed the first requirement to return the reversed order of the list and believe i messed up when creating a set then add data to the set, also something is wrong with returning the keys of the dictionary
>
>
> can someone point out the error in my code and the meaning of the unittes error?
You're nearly there.
After you've called the function, anything you do to the result is not
done BY the function and will therefore not be done when called by other
code.
The unit test that calls the function will not do those things. It
expects them to already be done.
So ... what changes to your function do you think would fix that?
Regards,
E.
[toc] | [prev] | [next] | [standalone]
| From | lee <malitician@gmail.com> |
|---|---|
| Date | 2015-12-27 12:26 -0800 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <423fff7a-ea6a-4949-be99-f13cce6f360e@googlegroups.com> |
| In reply to | #100905 |
>
> After you've called the function, anything you do to the result is not
> done BY the function and will therefore not be done when called by other
> code.
>
> The unit test that calls the function will not do those things. It
> expects them to already be done.
>
> So ... what changes to your function do you think would fix that?
>
> Regards,
> E.
i modified my code a little but still no luck, the same unit test error surfaced again.
here is the modified code
def manipulate_data(kind, data):
if kind == 'list':
return list(data)[::-1]
elif kind == 'set':
return set(data)
elif kind == 'dictionary':
return dict( 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}).keys()
[toc] | [prev] | [next] | [standalone]
| From | Prince Udoka <princeudo52@gmail.com> |
|---|---|
| Date | 2015-12-27 12:32 -0800 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <5e43da5b-01e8-4395-a04c-dc311844a617@googlegroups.com> |
| In reply to | #100904 |
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()
[toc] | [prev] | [next] | [standalone]
| From | lee <malitician@gmail.com> |
|---|---|
| Date | 2015-12-27 12:54 -0800 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <463ca880-2af7-42fa-93ca-dcf6187c6a4d@googlegroups.com> |
| In reply to | #100916 |
On Sunday, December 27, 2015 at 9:32:24 PM UTC+1, 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()
so how did you call the function because just pasting your code as it is did not work for me. sorry if question sounds dumb
[toc] | [prev] | [next] | [standalone]
| From | Erik <python@lucidity.plus.com> |
|---|---|
| Date | 2015-12-27 21:42 +0000 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <mailman.36.1451252585.11925.python-list@python.org> |
| In reply to | #100916 |
On 27/12/15 20: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()
Please stop posting code to the list which you have not even attempted
to run. This is getting a bit silly.
RUN your code. Three of the four paths through that code will fail when
it is run, so I am sure that you have not.
If you don't understand the error messages then ask what they mean,
along with your guess at what you think they mean and what you tried to
do about it (but did not work).
Please consider joining a list which is more appropriate for these
questions:
https://mail.python.org/mailman/listinfo/tutor/
E.
[toc] | [prev] | [next] | [standalone]
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Date | 2015-12-28 14:32 +1100 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <mailman.37.1451273591.11925.python-list@python.org> |
| In reply to | #100916 |
On 27Dec2015 12:32, Prince Udoka <princeudo52@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 <cs@zip.com.au>
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2015-12-20 01:51 +0000 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <mailman.62.1450576315.30845.python-list@python.org> |
| In reply to | #100615 |
On 20/12/2015 01:09, Michael Torrie wrote:
> On 12/19/2015 05:41 PM, Mark Lawrence wrote:
>> On 19/12/2015 23:19, malitician@gmail.com wrote:
>>> you are absolutely correct Mark
>>> i'm a beginner in python and from the original question and test case given above i wrote this
>>>
>>> class BankAccount(object):
>>> def __init__(self, initial_balance=0):
>>> self.balance = initial_balance
>>> def deposit(self, amount):
>>> self.balance +=amount
>>> def withdraw(self, amount):
>>> self.balance -= amount
>>> my_account = BankAccount(90)
>>> my_account.withdraw(1000)
>>> if my_account.balance < 4:
>>> print('invalid transaction')
> ^^^^^^^^^^^^^^^^^^
> This code probably belongs in the withdraw() method.
>
>>> class MinimumBalanceAccount(BankAccount):
>>> def __init__(self, MinimumBalance=4):
>>> self.minbalance = MinimumBalance
>>>
>>> after executing this i got this TEST SOLUTION ERROR which i don't know what it means
>>>
>>> {"finished": true, "success": [{"fullName": "test_balance", "passedSpecNumber": 1}, {"fullName": "test_deposit", "passedSpecNumber": 2}, {"fullName": "test_sub_class", "passedSpecNumber": 3}, {"fullName": "test_withdraw", "passedSpecNumber": 4}], "passed": false, "started": true, "failures": [{"failedSpecNumber": 1, "fullName": "test_invalid_operation", "failedExpectations": [{"message": "Failure in line 23, in test_invalid_operation\n self.assertEqual(self.my_account.withdraw(1000), \"invalid transaction\", msg='Invalid transaction')\nAssertionError: Invalid transaction\n"}]}], "specs": {"count": 5, "pendingCount": 0, "time": "0.000065"}}
>>> -910
>>> invalid transaction
>>>
>>> SO please what is wrong with my code, does it not meet the requirement of the "test case" given above in the question?
>>> Thanks in advance
>>>
>>
>> It's a start but you've still left things out. If I run your code as
>> given above it outputs "invalid transaction", exactly as expected. So
>> how are you running the code? Where does the extra output you give
>> above come from, presumably the "test case", whatever that might be?
>
> While the output is as we'd expect, the program's logic is probably
> wrong. Would not you want to put that logic in the withdraw method to
> prevent an invalid transaction?
>
Frankly I've no idea on the grounds that I simply cannot be bothered to
look, and at this time of the night/early morning I'm not inclined to
play guessing games. Perhaps the OP would be kind enough to provide the
requirements and his/her code in one hit, the answer can be one hit, and
we happily move on to Boxing day.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | anyanwuchukwuemeka9@gmail.com |
|---|---|
| Date | 2016-03-19 14:40 -0700 |
| Message-ID | <b3717770-d902-4d8f-a2d3-c4af96e9f18a@googlegroups.com> |
| In reply to | #100609 |
What was the final answer for the create class bankaccount question?
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2016-03-19 18:03 -0400 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <mailman.400.1458425024.12893.python-list@python.org> |
| In reply to | #105287 |
On Sat, Mar 19, 2016 at 5:40 PM, <anyanwuchukwuemeka9@gmail.com> wrote: > What was the final answer for the create class bankaccount question? > -- > https://mail.python.org/mailman/listinfo/python-list > Was it 14? -- Joel Goldstick http://joelgoldstick.com/ <http://joelgoldstick.com/stats/birthdays> http://cc-baseballstats.info/
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2016-03-19 22:24 +0000 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <mailman.401.1458426297.12893.python-list@python.org> |
| In reply to | #105287 |
On 19/03/2016 21:40, anyanwuchukwuemeka9@gmail.com wrote: > What was the final answer for the create class bankaccount question? > 42. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2016-03-20 11:26 +1100 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <mailman.402.1458433609.12893.python-list@python.org> |
| In reply to | #105287 |
anyanwuchukwuemeka9@gmail.com writes: > What was the final answer for the create class bankaccount question? The final answer is: homework entails that you do the work, not us. -- \ “I tell you the truth: some standing here will not taste death | `\ before they see the Son of Man coming in his kingdom.” —Jesus, | _o__) c. 30 CE, as quoted in Matthew 16:28 | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2015-12-20 11:04 +0000 |
| Message-ID | <n5620i$3do$1@dont-email.me> |
| In reply to | #100324 |
On Sat, 12 Dec 2015 01:05:01 -0800, Harbey Leke wrote: > Create a class called BankAccount > > .Create a constructor that takes in an integer and assigns this to a > `balance` property. > > .Create a method called `deposit` that takes in cash deposit amount and > updates the balance accordingly. > > .Create a method called `withdraw` that takes in cash withdrawal amount > and updates the balance accordingly. if amount is greater than balance > return `"invalid transaction"` > > .Create a subclass MinimumBalanceAccount of the BankAccount class > > Please i need help on this i am a beginer into python programming. It sounds like you're taking a python course. Your course should have taught you all you need to carry out this programming task before setting this exercise. If you have not been paying attention, have failed to attend some sessions, or have not been keeping up with the course in some way, that might explain your difficulty. Perhaps you should approach the course tutors and ask for some remedial assistance. Alternatively, if you have so far been a fully attending, attentive and straight A student on this course, perhaps they are setting exercises for which they have not previously provided the necessary tuition. If that is the case, I suggest you ask them to reimburse your course fees, and then go and find better tutors. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2015-12-20 22:29 +1100 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <mailman.1.1450610958.2237.python-list@python.org> |
| In reply to | #100626 |
On Sun, Dec 20, 2015 at 10:04 PM, Denis McMahon <denismfmcmahon@gmail.com> wrote: > It sounds like you're taking a python course. Your course should have > taught you all you need to carry out this programming task before setting > this exercise. > > Alternatively, if you have so far been a fully attending, attentive and > straight A student on this course, perhaps they are setting exercises for > which they have not previously provided the necessary tuition. There is a half-and-half possibility, too; sometimes a course will give you a challenge, and *then* introduce you to the techniques necessary for solving it (after letting you have a shot at it on your own). I don't like that style, myself, but it does exist, so it may be worth skimming forward a few sections in the course to see what it teaches next. But frankly, I doubt that's what's going on here. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | jeanbigboute@gmail.com |
|---|---|
| Date | 2015-12-25 20:15 -0800 |
| Subject | Re: Need help on a project To :"Create a class called BankAccount with the following parameters " |
| Message-ID | <e33ee506-5c24-4c82-89b1-b631d9c981da@googlegroups.com> |
| In reply to | #100628 |
On Sunday, December 20, 2015 at 3:29:30 AM UTC-8, Chris Angelico wrote: [... much instruction deleted] > There is a half-and-half possibility, too; sometimes a course will > give you a challenge, and *then* introduce you to the techniques > necessary for solving it (after letting you have a shot at it on your > own). I don't like that style, myself, but it does exist, so it may be > worth skimming forward a few sections in the course to see what it > teaches next. > > But frankly, I doubt that's what's going on here. It sounds to me like the one or or more about the course may be true: a) It is being offered in a country where English is not the native language b) It may not have provided the needed background c) It suggests that students get help by posting to public discussion groups I found these sites useful when I was learning about classes in Python. Perhaps it will help these students: https://www.jeffknupp.com/blog/2014/06/18/improve-your-python-python-classes-and-object-oriented-programming/ http://anandology.com/python-practice-book/object_oriented_programming.html
[toc] | [prev] | [next] | [standalone]
Page 2 of 6 — ← Prev page 1 [2] 3 4 5 6 Next page →
Back to top | Article view | comp.lang.python
csiph-web