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 trialDeepak Nautiyal
7,235 Points[Solved] NameError: name 'Monster' is not defined
Below code give above error. Not sure why?
import monster
class Dragon(Monster): size = 10
import monster
class Dragon(Monster):
size = 10
2 Answers
crosscheckking
25,155 PointsYou need to use
from monster import Monster
otherwise you would need to use
class Dragon(monster.Monster):
for it to work, but the problem is asking for the above example where you use the from monster import Monster statement.
Deepak Nautiyal
7,235 PointsThanks for the quick response John Lindsey This solves the issue :)
crosscheckking
25,155 Pointscrosscheckking
25,155 PointsI just tested it in the code challenge and they will actually both work. So you can choose whichever you prefer.
crosscheckking
25,155 Pointscrosscheckking
25,155 PointsJust to clarify, here would be either code you could use:
This is because the first import statement is importing the entire monster file so you need to then specify that you want the Monster class from the monster.py file. If you use the from monster import Monster, then you are just importing the Monster class and can refer to it just as Monster.