[Tutor] Help regarding lists, dictionaries and tuples
Robert Sjöblom
robert.sjoblom at gmail.com
Mon Nov 22 00:29:36 CET 2010
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?
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.
In a somewhat related note: the book gives quite hard challenges, the
coin flip challenge discussed here a few days ago, for example, comes
before the reader learns about for loops.
Thanks in advance, and best regards,
Robert S.
More information about the Tutor
mailing list