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

Bummer: Didn't get `D20`s in my `Hand` instance

I'm not sure where I went wrong

dice.py
import random


class Die:
    def __init__(self, sides=2):
        if sides < 2:
            raise ValueError("Can't have fewer than two sides")
        self.sides = sides
        self.value = random.randint(1, sides)

    def __int__(self):
        return self.value

    def __add__(self, other):
        return int(self) + other

    def __radd__(self, other):
        return self + other


class D20(Die):
    def __init__(self):
        super().__init__(sides = 20)
hands.py
from dice import D20

class Hand(list):

    def __init__(self, *args, **kwargs):
        super().__init__()

    @classmethod
    def roll(cls, size):
        num = []
        for item in range(size):
            num.append(D20().value)
        return num

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

3 Answers

I tested ur code. It works fine. If u still have problem try this one (https://teamtreehouse.com/community/how-does-sumself-work)

Austin Loos
Austin Loos
7,046 Points

I believe the problem is that the autograder is looking for instances of D20, but instead of getting a class object, it's getting .value of the object. Try appending just D20() to num instead of D20().value

Hello Amelia, thank you for requesting my help.

However, your coding and the problem with the coding looks super advanced. I am at the beginner's level of Python and I am also not learning the programming language anymore as I have decided to focus on something else for now. Therefore, I won't be able to provide the appropriate help to you. I am sorry that I couldn't be of help.

I hope that other people provide you with the help that you need.

Kind regards,

Mary.