Python lists and Math

  • From: BlueScale <bluescale1976@xxxxxxx>
  • To: "programmingblind@xxxxxxxxxxxxx" <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 19 Oct 2008 08:40:13 -0400

Hi,
In my effort to learn Python, I have written a dice class.  I have a
roll method that accepts one argument, the number of dice to roll.  It
returns a list of the results.  In the program I wrote to test the
class, I have something like:
score = roll.roll(1)
This rolls 1 six sided die.  The problem I run in to is when I try to
do:
score += roll.roll(1)
I get an error about the += operand not supporting list and int.  So my
next move was to try:
score += int(roll.roll())
Which Python says can't be done because the number is stored in a list,
not a string.  So, my question is, how do I keep track of the score?  IS
there some function to convert lists to int?
Thanks for the help

Other related posts: