[Tutor] Help regarding lists, dictionaries and tuples
bob gailer
bgailer at gmail.com
Mon Nov 22 06:15:08 CET 2010
On 11/21/2010 6:29 PM, Robert Sjöblom wrote:
> Hi. I'm new at programming and, as some others on this list, am going
> through Python Programming for the Absolute Beginner. In the current
> chapter (dealing with lists and dictionaries), one of the challenges
> is to:
>> Write a Character Creator program for a role-playing game. The player should be given a pool of 30 points to spend on four attributes: Strength, Health, Wisdom, and Dexterity. The>player should be able to spend points from the pool on any attribute and should also be able to take points from an attribute and put them back into the pool.
> I don't want a direct answer on how to proceed, but a question that
> arose during my thinking of the problem was whether dictionaries can
> have integral data in them, like so:
> attributes = {"Strength" : 28, "Health" : 12}
> or if they have to be:
> attributes = {"Strength" : "28", "Health" : "12"}
>
> Ok, I'm clearly thinking in circles here. I used the interpreter to
> figure out that both are fine but the first example has integers,
> whereas the second has strings. Good to know. What I'm wondering then,
> instead, is whether there's a good way to sum up the value of integral
> data in a dictionary?
Why would you want to sum them? You start with 30 points in the pool,
then allocate them to the attributes. The sum will still be 30.
> I suppose I could solve the challenge by setting up 4 different
> variables and going at it that way, but since the challenge is listed
> in a chapter dealing with Lists and Dictionaries (and tuples), I
> figure there should be some way to solve it with those tools.
>
--
Bob Gailer
919-636-4239
Chapel Hill NC
More information about the Tutor
mailing list