Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51992

Re: Creating a running tally/ definitely new to this

References <9e9e6a5a-5f8e-46b4-91dc-757fc74348d9@googlegroups.com>
From Joshua Landau <joshua@landau.ws>
Date 2013-08-06 02:56 +0100
Subject Re: Creating a running tally/ definitely new to this
Newsgroups comp.lang.python
Message-ID <mailman.225.1375754670.1251.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web