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

Python Object-Oriented Python Dice Roller RPG Roller

Anthony Baulo
Anthony Baulo
9,234 Points

RPG Roller- Works in my IDE (including total and length) but code challenge gives Error: Can't get length of hand

import dice

class Hand(list):
    def __init__(self, size=0, die_class=None, *args, **kwargs):
        super().__init__()

        for _ in range(size):
            self.append(die_class())
        self.sort()

    @property
    def total(self):
        return sum(self)

    @classmethod
    def roll(cls, size=0, die_class=dice.D20):
        return cls(size, die_class)

new_roll = Hand.roll(2)

print(new_roll)
print(new_roll.total)
print(len(new_roll))

The output is:

[9, 14]

23

2

The roll method should be using the parent Hand class to create an instance of a list, passing it the size and die_class properties that it needs. Therefore new_roll should be a proper list, which includes having a length. My IDE seems to agree. What am I overlooking?

Thanks for your help!