I have the following code here:
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()
I know this code appears as the correct answer, but I was just wondering... Why doesn't the code work if I just call this instead?
print my_triangle.number_of_sides my_triangle.check_angles()
I saw "return" in the check angles method, so I figured there would be no need to actually use the print function. However, when I tried this it only displayed the first line. Could someone explain why this wouldn't work and when to use "print" and when to use "return"?
Sorry if I couldn't extrapolate my question well enough. Thanks!