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

spencer tintorri
spencer tintorri
6,184 Points

Why does ```hand.die_class``` and ```hand.size``` throw an AttributeError

We set size=5 and die_class=D6, but we get "AttributeError: 'Hand' object has no attribute 'size' / 'die_class' "

hand = Hand(size=5, die_class=D6)
print(hand[0].value)
print(len(hand))
print(hand.die_class)

1 Answer

Steven Parker
Steven Parker
229,732 Points

The arguments passed to create a new instance don't automatically become attributes in the class. Based on the code, they might, but this code doesn't retain either argument that way.

The "size" argument determines how many objects will be initially stored in the Hand, and "die_class" determines what kind of objects they will be.