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 trialTomas Salas
Front End Web Development Techdegree Graduate 37,934 Pointsself.value = value or random.randint(1, sides) NameError: name 'sides' ?
I do not understand why the compiler is given me a name error with this code
import random
class Die:
def init(self, sides = 2, value = 0):
if not sides >= 2:
raise ValueError("Must have at lest 2 sides")
if not isinstance(sides, int):
raise ValueError("Sides most be a whole number")
self.value = value or random.randint(1, sides)
1 Answer
Steven Parker
231,248 PointsThe issue might be related to indentation, which can only be seen if you post the code using Markdown formatting.
Providing a link to the course page would also be helpful.