12.Inheritance syntax help me


#1



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


#3

help me out of this @leonhard.wettengmx.n


#4

I have the same problem. I'm pretty sure everything is typed right but I get an error


#5

What exactly is the error you are getting?


#6

Post entire code please


#7

Did you create a class called Triangle?


#8

class Triangle(object):
def init(self, angle1, angle2, angle3):
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3

number_of_sides = 3

def check_angles(self):
    if self.angle1 + self.angle2 + self.angle3 == 180:
        return True
    else:
        return False

my_triangle = Triangle(90, 60, 30)

class Equilateral(Triangle):
angle = 60
def init(self):
self.angle1 = self.angle
self.angle2 = self.angle
self.angle3 = self.angle


#9

Post the entire code, that part looks fine to me.


#10

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, side1, side2, side3):
self.side1 = side1
self.side2 = side2
self.side3 = side3

In the class Triangle, you recreate the __init____ method so it knows where to get the information from.((Make sure to have correct indentation[4 spaces on next line after :])


#11

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, side1, side2, side3):
self.side1 = side1
self.side2 = side2
self.side3 = side3

In the class Triangle, you recreate the __init____ method so it knows where to get the information from.((Make sure to have correct indentation[4 spaces on next line after :])


#13

hi there @swazi_kunene,

this part is wierd
the following code works...

    def __init__(self, angle1, angle2, angle3):
        selfangle1 = angle1
        self.angle2 = angle2
        self.angle3 = angle3
    number_of_sides = 3
    def check_angles(self):
        if self.angle1 + self.angle2 + self.angle3 == 180:
            return True
        else:
            return False
my_triangle = Triangle(90, 45, 45)
print my_triangle.number_of_sides
print my_triangle.check_angles()

let me know if there are anymoore problems :slight_smile:


#14

There were no problems and sorry for the delay.