Getting result but I'm getting asked if i created a instance


#1

https://www.codecademy.com/en/courses/python-intermediate-en-WL8e4/3/3?curriculum_id=4f89dab3d788890003000096#

Im having a issue where Im getting the correct answer but it will not let me continue. It keeps asking if I created a instance called my_triangle which I have. Its frustrating when this happens as Ive encountered throughout the course but Im really stumped to what it wants me to do.
In my eyes my code is correct but maybe Im wrong… any help is much appreciated



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(30, 60, 90)        
            
    print my_triangle.number_of_sides
    print my_triangle.check_angles()
            
        



#2

you created the class instance inside the class.

Remember, classes are like blueprints and the instances are the things build from the blue print.

So, lets say you build a house, you start with the blueprint (class), then after the blueprint is finished, you start building the house (instance)

what you currently did is start building the house (instance) while still working on the blueprint (class), and then hoping everything will pan out right.


#3

Thanks so much man… I thought I tried different indentations but I guess I never pulled it outside the class. Thanks for the info though… very well explained. Still having a bit of difficulty understanding classes.


#4

You’re welcome :slight_smile: Yea, classes are a bit tricky but with a bit of practice you will get the hang of it :slight_smile:


#5