Tried to use the documentation but still getting the errors...

The 1st one has to do with the available_points

# set variables
attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
MAX_POINTS = 30
available_points = MAX_POINTS - attributes.values()
keys = attributes.keys()
values = attributes.values()

this is the error i'm getting...

Traceback (most recent call last):
  File "C:\Users\Public\Documents\My Python programs\role_playing_game1.py",
line 8, in <module>
    available_points = MAX_POINTS - attributes.values()
TypeError: unsupported operand type(s) for -: 'int' and 'dict_values'

I know using attributes.values here isn't correct but I can't figure out how
to put the sum of the values into that equation.

I looked up this part f the docs...
http://docs.python.org/py3k/library/stdtypes.html?highlight=values#dict.values
and tried to copy the format into my program. I am attempting to get the
total of the values of everything in my dictionary.   Not sure what is
different between my 'attributes' dictionary and the 'dishes' dictionary
they use.  I used the following code and got the following error.

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

#point allocation
point_total = 0
for val in values:
  point_total += val
  print (point_total)

and get this error...

Traceback (most recent call last):
  File "C:\Users\Public\Documents\My Python programs\role_playing_game1.py",
line 26, in <module>
    point_total += val
TypeError: unsupported operand type(s) for +=: 'int' and 'str'




On Tue, Dec 7, 2010 at 10:06 AM, Peter Otten <__pete...@web.de> wrote:

> Al Stern wrote:
>
> > Apologies for all my questions.  Up to this point I have been able to
> work
> > out most of the challenges but I seem to have hit a wall.  Can't seem to
> > make any progress and completely frustrated.
> >
> > I looked at the 11/21 discussion.  From the documentation, I realized I
> > needed to set the variables to view the keys and values.  Getting an
> error
> > though.
> >
> > attributes = {"strength": 0, "health": 0, "wisdom": 0, "dexterity": 0}
> > MAX_POINTS = 30
> > keys = attributes.viewkeys()
> > values = attributes.viewvalues()
> >
> > Traceback (most recent call last):
> >   File "C:\Users\Public\Documents\My Python
> >   programs\role_playing_game1.py",
> > line 8, in <module>
> >     keys = attributes.viewkeys()
> > AttributeError: 'dict' object has no attribute 'viewkeys'
>
> The dictionary methods you are looking for are called keys() and values()
> not viewkeys() or viewvalues(). They do return view objects which may be
> causing the confusion. Have a look at the documentation at
>
> http://docs.python.org/dev/py3k/library/stdtypes.html#dictionary-view-
> objects
>
> which shows a simple example.
> By the way you, can use the interactive interpreter to find out what
> attributes an object has to offer:
>
> $ python3
> Python 3.1.1+ (r311:74480, Nov  2 2009, 15:45:00)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> d = {"a": 1, "b": 2}
> >>> dir(d)
> ['__class__', '__contains__', '__delattr__', '__delitem__', '__doc__',
> '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',
> '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__',
> '__lt__',
> '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
> '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__',
> 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem',
> 'setdefault', 'update', 'values']
>
> Peter
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to