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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Adam Siwiec](https://uploads.teamtreehouse.com/production/profile-photos/891202/micro_me.jpg)
Adam Siwiec
12,070 PointsOOP question
Why do I get an NameError on numberCorrect for this class/method:
from questions import GenerateQuestion
class Quiz:
numberCorrect = 0
def take_quiz(self):
GenerateQuestion(self.numberCorrect,"+")
Here is my GenerateQuestion class:
import random
class GenerateQuestion:
text = None
answer = None
num1 = None
num2 = None
maxnum = 0
def __init__(self, scale, symbol):
self.maxnum = 2 ** scale
self.num1 = random.randint(1,self.maxnum)
self.num2 = random.randint(1,self.maxnum)
self.text = "{} {} {}".format(self.num1,symbol,self.num2)
if symbol == "+":
self.answer = self.num1 + self.num2
if symbol == "-":
self.answer = self.num1 - self.num2
if symbol == "*":
self.answer = self.num1 * self.num2
if symbol == "/":
self.answer = self.num1 // self.num2
Wairton Rebouças
8,225 PointsWairton Rebouças
8,225 PointsI've tested your code, it seems to be working fine on both python 2 and 3 on my machine. This is part of some quiz? If you are running this on your computer, what error message you got?