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 Giving a Hand

Amir Shahabnia
Amir Shahabnia
29,310 Points

Get AttributeError while trying to get hand[0].value

I am trying to get the value from an instance of the Hand class but I get an

AttributeError when I try hand[0].value assigned with die_class=D6. 

Everything seems to be working but not the value of each of dices. Please help :))

Here is my code for the class:

class Hand(list):
    def __init__(self, size=0, die_class=None, *args, **kwargs):
        if not die_class:
            raise ValueError("You must provide a die class")
        super().__init__()


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

Below is my code implemented on terminal including the Attribute Error:

>>> from dice import D6
>>> from hands import Hand
>>> hand = Hand(size=5, die_class=D6)
>>> hand[0]
<class 'dice.D6'>
>>> hand[0].value
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'D6' has no attribute 'value'

1 Answer

Nehemie Balukidi
Nehemie Balukidi
405 Points

Hi there, the error says that a D6 object does not have an attribute named value. Can you try to do something like: dir(D6) or dir(hand[0]) to see the attributes of a D6 object, post the output back if you still can't find a way forward? so we can try to help