[Tutor] role playing game - help needed

Al Stern albstern at gmail.com
Tue Dec 7 05:27:50 CET 2010


Ok.  I think I am starting to get it but still not sure how to separate the
value from the key.  Once I have this...

attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
MAX_POINTS = 30

How do I set the variable for available_points?

available_points = MAX_POINTS - (not sure what goes here)

I am pretty sure I will change the values by something like this...

attributes["strength"] = input("\nHow many points do you want to assign to
strength?: ")

Please let me know if this isn't advisable.  It seems to work on the
surface.

On Mon, Dec 6, 2010 at 1:16 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

>
> "Al Stern" <albstern at gmail.com> wrote
>
>
> Thanks for the advice.  I think I have the dictionary function set up right
>> now although I'm still not clear why it is better than the list.
>>
>> attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
>>
>
> Consider where you want to update the points for "health"
>
> Using two lists you need to loop over the keys list to find the index
> of "health" then access the values list to set the points. Something
> like this:
>
> for x in range(len(keys)):
>   if keys[x] == "health":
>       values[x] = newValue
>
> With a dictionary you just need to do
>
> attributes["health"] = newValue
>
> That's a lot less typing and will be faster performance too.
> I'd also say its a lot easier to see whats happening - its more readable.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101206/776601fa/attachment-0001.html>


More information about the Tutor mailing list