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
Brad Pettigrew
1,834 PointsTrouble with classes and variables
Hey, I'm having some trouble with my code in the python track. I keep getting an error on the last line stating that the list 'questions' is undefined. I think this has something to do with where I've declared my variable.
class Quiz:
questions = []
answers = []
#so we can log a list of right/wrong on each question index
def __init__(self):
#generate 10 rand questions with numbers 1 to 10
#add these to questions
for num in range(0,10):
type = random.randint(1,2)
if type == 1:
newquestion = Add(random.randint(1,10), random.randint(1,10))
elif type == 2:
newquestion = Multiply(random.randint(1,10), random.randint(1,10))
questions.append(newquestion)
1 Answer
Gordon Reeder
2,521 PointsYou need to reference self.
self.questions.append(newquestion)