12. Inheritance Syntax


#1

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/introduction-to-classes/exercises/inheritance-syntax?action=lesson_resume&link_content_target=interstitial_lesson
An error message keeps popping up that says it expected an indented block. How do I fix this? My code seems right to me, I would appreciate some help.

class Shape(object):
    """Makes shapes!"""
    def __init__(self, number_of_sides):
        self.number_of_sides = number_of_sides

class Triangle(Shape):
  def __init__(self, sidel, side2, side3):
  	self.side1 = side1
  	self.side2 = side2
  	self.side3 = side3

#2

Hi @terasurfer40545,

Sometimes when indentation looks correct, but the Python interpreter reports that it is not, the cause is that the code contains a mixture of spaces and tabs for indentation.

As you might be able to discern by slowly selecting the indented areas, these three lines have each been indented with spaces followed by a tab …

  	self.side1 = side1
  	self.side2 = side2
  	self.side3 = side3

Remove all the indentation from each of those lines, and use all spaces to restore it. If that does not solve the problem, do the same with all the other lines that are indented.


#3

I see, thank you on that matter. However I have encountered another problem,
The interpreter returns the error to me : “Did you create a class called Triangle?” How should I solve this?

class Shape(object):
    """Makes shapes!"""
    def __init__(self, number_of_sides):
			self.number_of_sides = number_of_sides

# Add your Triangle class below!
class Triangle(Shape):
  def __init__(self, sidel, side2, side3):
    self.side1 = side1
    self.side2 = side2
    self.side3 = side3

#4

the error message doesn’t reflect the problem, lets see what happens when we create a class instance so we can any interpreter errors in the init method:

class Triangle(Shape):
  def __init__(self, sidel, side2, side3):
    self.side1 = side1
    self.side2 = side2
    self.side3 = side3
triangle = Triangle(60,60,60)

as you can see now, here:

self.side1 = side1

side1 is undefined. you misspelled in the line above when you attempted to define the side1 parameter


#5

Sorry I did not notice the error in my code, thank you for helping out!


#6

No need to apologize, i am sure you tried to debug it and couldn’t figure it out. That is why we have a forum :wink:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.