Class it Up


#1



I have a problem with the exercise above. The error is the following:
Oops, try again. Your code caused the following error: 'Triangle' object has no attribute 'anlge1'


class  Triangle(object):
    number_of_sides = 3
    def __init__(self, angle1, angle2, angle3):
        self.angle1 = angle1
        self.angle2 = angle2
        self.angle3 = angle3
    def check_angles(self):
        if self.anlge1 + self.angle2 + self.angle3 == 180:
            return True
        else:
            return False


If I manually add angle1, angle2 and angle3 as a variables to check_angles method like this:

class  Triangle(object):
    number_of_sides = 3
    def __init__(self, angle1, angle2, angle3):
        self.angle1 = angle1
        self.angle2 = angle2
        self.angle3 = angle3
    def check_angles(self, angle1, angle2, angle3):
        if self.anlge1 + self.angle2 + self.angle3 == 180:
            return True
        else:
            return False

then the error is following:

Oops, try again. Make sure to pass self as an argument to your check_angles method!

I'm lost here. Help?


#2

In first program, You need to check spelling!
check check_angles() method again in first program.

Use your error messages to hunt bugs.

Oops, try again. Your code caused the following error: 'Triangle' object has no attribute 'anlge1'

It says object has no anlge1 ?


#3

Oh, thank you. I was so angry that it does work for some people and doesn't work for me that I didn't take time to carefully read the name of the attribute. Theese kinds of mistakes are the worst.


#4

Whenever you get an error,check error message ,Many of the times solution used to be just step ahead!!
I'd say make a list of errors,That comes in handy and You will quickly able to hunt the bug.


#5

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