Python Object-Oriented Python Dice Roller RPG Roller

Kevin Apetrei
Kevin Apetrei
2,447 Points

Bummer: Can't get the length of a `Hand`

I'm supposed to make a list in a classmethod and append the returned value of method D20() for the total size.

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):
    @property
    def total(self):
        return sum(self)

    @classmethod
    def roll(cls, size=1):
        rollList = []

        for _ in range(size):
            rollList.append(D20())

1 Answer

Steven Parker
Steven Parker
201,997 Points

Your method doesn't currently "return" anything. It needs to return a new instance with the list in it.