[Tutor] role playing game - help needed
robert.sjoblom at gmail.com
Mon Dec 6 15:03:38 CET 2010
>I am starting with a book called Python Programming for the Absolute Beginner by Michael Dawson. The book has been >pretty good >and up to this point, I have grasped all the concepts it has covered. At the end of each chapter, there are a number of challenges you >need to complete before moving on. Problem is, I have gotten stumped on one in Chapter 5: Lists and Dictionaries.
> attributes = ["strength", "health", "wisdom", "dexterity"]
> points = [0,0,0,0]
> MAX_POINTS = 30
> available_points = MAX_POINTS - sum(points)
Before anyone comments that you can write a function for the points
system, which was helpful to me when I asked a question regarding that
very chapter: The book doesn't deal with functions until Chapter 6.
As for your problem, Alan; I believe Alan already answered it -- you
have two different lists, attributes and points, but a dictionary
would be easier to handle. Not to say that it couldn't be done the way
you're doing it though. A dictionary is built with key:value pairs.
Then it's just about figuring out a way to change the value associated
with each key when the attribute changes. I don't want to spoil the
challenge of working it out yourself, but when I asked I was told to
check out how values() and sum() worked.
More information about the Tutor