How can I assign my Equilateral angle values?

Question

How can I assign my Equilateral angle values?

Answer

Just like we did with the Triangle’s angle values, we are going to now assign the angle1, angle2, and angle3 values. This can be done like self.angleN = self.angle, since all angles are the same for an equilateral triangle.
The most common issues here are spelling-related, so double check your spelling! Also, be sure not to write the assignment backwards, like this: self.angle = self.angleN.

3 Likes

You don’t.
Or rather you do that in the definition, not in the instance creation. So if you mean how do you create an instance of the Equilateral object, you simply don’t send it any values. See the very end.

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.angle1 + self.angle2 + self.angle3 == 180:
      return True
    else:
      return False
    
class Equilateral(Triangle):
  angle = 60
  def __init__(self):
    self.angle1 = self.angle
    self.angle2 = self.angle
    self.angle3 = self.angle
    
# create a couple of triangles
    
isosceles = Triangle(45,45,90)
eqqy = Equilateral()
print eqqy.check_angles()
print isosceles.angle3
print eqqy.angle3
3 Likes

I was wondering why is it necessary to add a “self” before the angle value instead of just using “self.angle1 = angle”, I know it returns an error but I can’t understand why.

3 Likes

Hi there. I typed in exactly what @ericgrossdesign provided (figured it out by myself), but it was not being accepted. It is saying:
It looks like **init** () is missing from Equilateral AND/OR Triangle.
class Equilateral(Triangle):
angle = 60
def __init__(self):
self.angle1 = self.angle
self.angle2 = self.angle
self.angle3 = self.angle

1 Like

Had the same issue, just ended up clicking the solution button which populated the same code I had typed but now it worked. Super weird.

2 Likes

same issue here. the solution is exactly the same, except that I didn’t put parentheses for the if statement in check_angles()
EDIT: I replaced my code with the solution and the error still popped out… unable to proceed

1 Like

Welcome to the forums!

Please post your code (not a copied solution) and the link to the lesson here so we can better see what went wrong.

I don’t see a solution to this issue, and I’m having the same problem.
I checked my spelling and indentation, and everything looks correct to my amateur eye.
Below is the code I wrote before I checked the forums:

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, 30, 60)

print my_triangle.number_of_sides
print my_triangle.check_angles()

class Equilateral(Triangle):
def init(self):

self.angle1 = 60
self.angle2 = 60
self.angle3 = 60

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

class Equilateral(Triangle):
  def __init__(self):

    self.angle1 = 60
    self.angle2 = 60
    self.angle3 = 60

Welcome to the forums!

The exercise wants us to create a class variable, angle, and set its value to 60. It then wants us to assign self.angle1, self.angle2, and self.angle3 equal to the class variable angle. While your solution does set all three angles to 60, the exercise wants us to set the three angles to a variable that holds the value 60. What change do you need to make?

understood
thank you

1 Like

Sorry to keep being a bother.

I’ve created the variable, and set the angles to the angle, but I don’t think that was the cause of the “It looks like init () is missing from Equilateral AND/OR Triangle.” error.

I’ve tried placing the angle variable both in the init function and outside (the lessons show it outside) and I’ve tried using “self.angle1 = angle” and self.angle1 = self.angle" neither way works. Again, I think these are independent of the ‘init’ error I’m getting, which is making the other details harder to track.

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

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

Because angle is a class variable and not an instance variable, you should use self.angle1 = angle rather than self.angle1 = self.angle.

As for the error you’re getting, it might be because your declaration of the __init__ method in the Triangle class has a space between the method name and the opening bracket for the method arguments (should be def __init__(self, angle1, angle2, angle3), not def __init__ (self, angle1, angle2, angle)).

ok, I removed the space after the init and changed all the 'self.angle’s to 'angle’s, but I"m still getting the init missing error

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

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

sorry to keep being a pest, but this is really annoying. The previous lessons passed, which were before adding the ‘Equilateral’ class. There isn’t anything different about the init in Equilateral that I can tell. I don’t know why I would suddenly get this error.

Sorry, my bad; earlier, I mentioned you should use self.angle1 = angle. Instead, it should be self.angle1 = self.angle or self.angle1 = Equilateral.angle. The following topic explains this.

If none of the above options work, try using the “Get Unstuck” button and accessing the solution. It seems like something may have gone wrong in terms of solution validation in this exercise.

1 Like

i have this misstake pls help me

It looks like init () is missing from Equilateral AND/OR Triangle.

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.angle1 + self.angle2 + self.angle3) == 180:

        return True

      else:

        return False

class Equilateral(Triangle):

  angle = 60

  def __init__(self):

        self.angle1 = self.angle

        self.angle2 = self.angle

        self.angle3 = self.angle

its bug in codecademy.com need use view solution or u cant finish it
codecademy.com

I’ve had the same error message and the only way to move on is simply to replace my own code with the solution code (editing my own code to make it identical did not work)

Welcome to the forums!

Maybe try copying and pasting the solution code into the code editor and running the exercise? If the exercise still doesn’t let you pass, you can submit a bug report in either the Community: Bug Reporting category on the forums or in the “Submit a Bug Report” section when you click “Get Unstuck”.

I am stuck as well - I typed the following code

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.angle1 + self.angle2 + self.angle3 == 180:
      return True
    else:
      return False

my_triangle = Triangle(90,40,50)
print my_triangle.check_angles()
print my_triangle.angle1

class Equilateral(Triangle):
  angle = 60

  def __init__(self):
    self.angle1 = self.angle
    self.angle2 = self.angle
    self.angle3 = self.angle    

Which is identical to the provided solution code apart from some spacing + prints from previous exercise and I receive the error:

It looks like init() is missing from Equilateral AND/OR Triangle.

As of now, I am unable to complete the exercise, even when I use ‘Get Unstuck’ to paste the provided solution code

1 Like