Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Anders Tellefsen
10,351 PointsDon't understand whats wrong with my code
Hi, I am going through the OOP python course and got stuck on the RPG Roller challenge.
Thisis my code:
from dice import D20
class Hand(list): @property def total(self): return sum(self)
@classmethod
def roll(cls, dice_count):
cls.dice_list = []
for _ in range(dice_count):
cls.dice_list.append(D20)
return cls.dice_list
1 Answer
Steven Parker
243,228 PointsThe "cls" parameter represents the class itself, and it does not have a "dice_list" attribute.
But you can use it to create a new instance and then append dice to it (and then return it):
my_hand = cls()
Anders Tellefsen
10,351 PointsAnders Tellefsen
10,351 PointsThanks, I'll try that.