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 trialYuyang Peng
5,665 Pointshand.ones Shouldn't 1s,2s,3s,4s,5s be YatzyHand s property?
So in the YatzyScoreSheet class, Kenneth used hand.ones. Looking back and I found out that those values belong to YatsyHand instead of hand and Yatsyhand is a subclass of hand,so hand shouldn't have access to properties? Could someone explain this to me please?
class YatzyScoreSheet: def score_ones(self, hand): return sum(hand.ones)
2 Answers
Dave StSomeWhere
19,870 PointsThe "hand" defined in YatzyScoresheet is not referring to the class Hand - it is just the variable name used for the arguments (so it does seem confusing).
You'll notice that when testing the code, Kenneth imports and instantiates the YatzyHand class:
from hands import YatzyHand
from dice import D6
from scoresheets import YatzyScoresheet
hand = YatzyHand()
Does that make sense?
Anthony Grodowski
4,902 PointsI feel angry at Kenneth now because he didn't say what excatly hand
is doing there and I wasted like an hour on figuring that out because it completely didn't make sense until watching the rest of the video... SMH
Yuyang Peng
5,665 PointsYuyang Peng
5,665 Pointsahhh yeah, god I feel embarrassed, hahahhaha thank you Dave !