Creating a running tally/ definitely new to this
Joshua Landau
joshua at landau.ws
Mon Aug 5 21:56:08 EDT 2013
On 6 August 2013 02:01, <gratedmedia at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130806/5cfb505a/attachment.html>
More information about the Python-list
mailing list