Python Object-Oriented Python Dice Roller RPG Roller

Lynn Collins
Lynn Collins
9,779 Points

I'm about to lose my temper! Why is my code failing!!!

Keeps failing! Is this because I'm stupid?

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 Hand(list):
    def __init__(self, size = 0, die_class = D20):
        super().__init__()
        for _ in range(size):
            self.append(die_class())
        #self.sort()

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

    @property 
    def total(self):
        self.sort()
        return sum(self)
hands.py
class Hand(list):
    @property
    def total(self):
        return sum(self)

2 Answers

Lynn Collins
Lynn Collins
9,779 Points

It takes me much too long to learn this. Sometimes I wonder about my brain lol

benoit koch
benoit koch
3,875 Points

all good lol, we are all in the same boat. Just glad i could help!

Lynn Collins
Lynn Collins
9,779 Points

I'm sooooo embarrassed!