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!

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


Chiroi Niehus
Chiroi Niehus
6,729 Points

I Am Having Trouble With Workspaces in dice.py

I have just finished watching the video called Comparing and Combining Dice, and in my console, when I type this:

from dice import D6 d6 = D6() int(d6)

It keeps printing out any number from a range of 1 to 5. I copied Kenneth's code exactly, but I am still unsure why it is doing this. Please help!

1 Answer

Andrew Fellenz
Andrew Fellenz
12,170 Points

You need to import dice separately from instantiating the die object. Also, you aren't actually declaring it correctly.

# Import only D6 from dice, though in this case, you could just import the whole file.
from dice import D6

# create an instance, "d", of D6 that holds the value of 6. 
d = D6(6)

# You can access this value directly by typing d.value

will result in "d" having a static value of 6. The challenge that you are on and the challenges that follow it were the hardest of any Treehouse challenges for me. So hard, in fact, that I wrote a short terminal github tutorial explaining how the objects work in one of the challenges that you are about to do. The tutorial likely won't make sense until you get to that challenge, but that will be really soon. Here you go:


I hope that helps.

Mod Edit: Changed comment to answer so that it may be voted on or marked as best answer.