I don't understand why my code doesn't pass.

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

def verifier_angles(self):
if self.angle1 + self.angle2 + self.angle3 == 180:
return True
return False
mon_triangle = Triangle(90,30,60)
print mon_triangle.nombre_de_cotes
print mon_triangle.verifier_angles()

in the console

Traceback (most recent call last):
** File "python", line 15, in **
AttributeError: 'Triangle' object has no attribute 'verifier_angles'


@snakefinger33gmail.c ,

You posted your code without formatting it, so we cannot verify its indentation. If you did not indent this function header in the code that you submitted, the verifier_angles method will be interpreted as a global function ...

def verifier_angles(self):

Method definitions need to be indented within class definitions to which they belong.


My code is indented in my editor.


If that method header is indented too much, it would also cause the error because it would become part of the __init__ method. If we could see your code, formatted, we could help more effectively.

NOTE - added (June 27, 2016) - I copied your code, made sure __init__ is spelled properly, indented the code properly, and it works.


I post it with indentation but it doesn't appear in the message ยง
I don't know how to do.


Paste your code into the window, then add three back ticks on the line before it and three back ticks on the line after it, or paste it into the window, select all of it, and click the </> button above the window.

Added (June 27, 2016):
See How do I format code in my posts?.


Thank you.
I refreshed my page and finally the code works.


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