Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51990 > unrolled thread
| Started by | gratedmedia@gmail.com |
|---|---|
| First post | 2013-08-05 18:01 -0700 |
| Last post | 2013-08-07 13:02 +0100 |
| Articles | 6 — 3 participants |
Back to article view | Back to comp.lang.python
Creating a running tally/ definitely new to this gratedmedia@gmail.com - 2013-08-05 18:01 -0700
Re: Creating a running tally/ definitely new to this Joshua Landau <joshua@landau.ws> - 2013-08-06 02:56 +0100
Re: Creating a running tally/ definitely new to this gratedmedia@gmail.com - 2013-08-06 04:00 -0700
Re: Creating a running tally/ definitely new to this Dave Angel <davea@davea.name> - 2013-08-06 02:15 +0000
Re: Creating a running tally/ definitely new to this gratedmedia@gmail.com - 2013-08-06 08:24 -0700
Re: Creating a running tally/ definitely new to this Joshua Landau <joshua@landau.ws> - 2013-08-07 13:02 +0100
| From | gratedmedia@gmail.com |
|---|---|
| Date | 2013-08-05 18:01 -0700 |
| Subject | Creating a running tally/ definitely new to this |
| Message-ID | <9e9e6a5a-5f8e-46b4-91dc-757fc74348d9@googlegroups.com> |
I currently working on a game, where I need to maintain a running tally of money, as the player makes purchases as they navigate thru game. I not exactly sure how to do this in python. I know it is a fairly basic step, nonetheless. Any assistance would be greatly appreciated.
[toc] | [next] | [standalone]
| From | Joshua Landau <joshua@landau.ws> |
|---|---|
| Date | 2013-08-06 02:56 +0100 |
| Message-ID | <mailman.225.1375754670.1251.python-list@python.org> |
| In reply to | #51990 |
[Multipart message — attachments visible in raw view] — view raw
On 6 August 2013 02:01, <gratedmedia@gmail.com> wrote:
>
> I currently working on a game, where I need to maintain a running tally of
> money, as the player makes purchases as they navigate thru game. I not
> exactly sure how to do this in python. I know it is a fairly basic step,
> nonetheless. Any assistance would be greatly appreciated.
>
If I understand correctly you want to store the amount of money in a
variable as a number that can be changed from many places within the code.
Say you have:
money = 0
def do_some_adventuring():
... # Add some money
You can "add some money" with:
global money # Allow changing money from within the function
money += 10 # for example
Is that it?
----
Note that normally you'd have some class of player with a money attribute
which can be accessed, but as a guess from the question I'm not sure you
know about classes yet.
[toc] | [prev] | [next] | [standalone]
| From | gratedmedia@gmail.com |
|---|---|
| Date | 2013-08-06 04:00 -0700 |
| Message-ID | <591973bb-477e-48bd-a9a2-e644f342e1a8@googlegroups.com> |
| In reply to | #51992 |
Yes I want to store an amount of money which will change from many places within the code. Absolutely correct. I am very "green" to this, if you're familiar, with "dopewars" the concept is very similar. for my practice trials I used.. selection_b = input() and manually input an amount of money, and used a loop of: loop = 1 while loop < 5: just to get a feel of how it would work but, every time I travel to a new destination and buy something the amount of money is reset. And I am working to prevent this so that I can maintain a running tally until the loop is complete. > > > > > I currently working on a game, where I need to maintain a running tally of money, as the player makes purchases as they navigate thru game. I not exactly sure how to do this in python. I know it is a fairly basic step, nonetheless. Any assistance would be greatly appreciated. > > > > > > If I understand correctly you want to store the amount of money in a variable as a number that can be changed from many places within the code. > > > Say you have: > > > > > money = 0 > > > def do_some_adventuring(): > ... # Add some money > > > You can "add some money" with: > > > > global money # Allow changing money from within the function > > money += 10 # for example > > > Is that it? > > > ---- > > > Note that normally you'd have some class of player with a money attribute which can be accessed, but as a guess from the question I'm not sure you know about classes yet.
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-08-06 02:15 +0000 |
| Message-ID | <mailman.226.1375755352.1251.python-list@python.org> |
| In reply to | #51990 |
gratedmedia@gmail.com wrote:
>
> I currently working on a game, where I need to maintain a running tally of money, as the player makes purchases as they navigate thru game. I not exactly sure how to do this in python. I know it is a fairly basic step, nonetheless. Any assistance would be greatly appreciated.
(just to save you the pain later:
http://wiki.python.org/moin/GoogleGroupsPython
)
So what have you written so far? Is this a homework assignment and
you've been covering certain parts of Python in a certain order? Is it
part of learning some tutorial?
There are so many ways of accomplishing this sort of thing, that without
some constraints, there are a dozen reasonable responses. I'll try one:
in the class Player, you make a pair of methods, purchase() and
income(), which manipulate the instance attribute assets. Then you
make a property that returns the assets.
Class Player:
....
def purchase(self, amount):
self.assets -= amount
def income(self, amount):
self.assets += amount
def wealth(self):
return self.assets
--
DaveA
[toc] | [prev] | [next] | [standalone]
| From | gratedmedia@gmail.com |
|---|---|
| Date | 2013-08-06 08:24 -0700 |
| Message-ID | <8b372a3b-c71d-4e26-88ae-ce5e6239fc36@googlegroups.com> |
| In reply to | #51993 |
On Monday, August 5, 2013 10:15:30 PM UTC-4, Dave Angel wrote: > gratedmedia@gmail.com wrote: > > > > > > > > I currently working on a game, where I need to maintain a running tally of money, as the player makes purchases as they navigate thru game. I not exactly sure how to do this in python. I know it is a fairly basic step, nonetheless. Any assistance would be greatly appreciated. > > > > (just to save you the pain later: > > http://wiki.python.org/moin/GoogleGroupsPython > > ) > > > > So what have you written so far? Is this a homework assignment and > > you've been covering certain parts of Python in a certain order? Is it > > part of learning some tutorial? > > > > There are so many ways of accomplishing this sort of thing, that without > > some constraints, there are a dozen reasonable responses. I'll try one: > > > > in the class Player, you make a pair of methods, purchase() and > > income(), which manipulate the instance attribute assets. Then you > > make a property that returns the assets. > > > > > > > > Class Player: > > .... > > def purchase(self, amount): > > self.assets -= amount > > def income(self, amount): > > self.assets += amount > > def wealth(self): > > return self.assets > > > > > > -- > > DaveA This a project I am am working on. I am using "Learn Python the Hard Way". To best explain. I'm working on a game with a similar format to John Dell's Dopewars, but on Python. SO I've created the several destinations to travel, but now maintaining the "running tally (money)" has been my issue. I'm going to take your advice and play with code you posted. Please contact me with any more suggestions.
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua@landau.ws> |
|---|---|
| Date | 2013-08-07 13:02 +0100 |
| Message-ID | <mailman.320.1375893821.1251.python-list@python.org> |
| In reply to | #52050 |
On 6 August 2013 16:24, <gratedmedia@gmail.com> wrote: > On Monday, August 5, 2013 10:15:30 PM UTC-4, Dave Angel wrote: >> gratedmedia@gmail.com wrote: >> >> > I currently working on a game, where I need to maintain a running tally of money, as the player makes purchases as they navigate thru game. I not exactly sure how to do this in python. I know it is a fairly basic step, nonetheless. Any assistance would be greatly appreciated. >> >> (just to save you the pain later: >> >> http://wiki.python.org/moin/GoogleGroupsPython >> >> ) Look! A link! Read it! > This a project I am am working on. I am using "Learn Python the Hard Way". To best explain. I'm working on a game with a similar format to John Dell's Dopewars, but on Python. SO I've created the several destinations to travel, but now maintaining the "running tally (money)" has been my issue. I'm going to take your advice and play with code you posted. Please contact me with any more suggestions. You're doing something wrong. No-one on this list knows what it is. Hence no-one can help you until you give us some way of finding out.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web