<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
<What do you expect to happen instead?>
This code gave me a pass @appylpye I feel there is something still wrong
question
I thought in the method (self ) always needs to be there but I add it gives me error reading
Oops, try again. milton.full_time_wage(0) caused the following exception: calculate_wage() takes exactly 2 arguments (3 given)
however, when entered as below it gives me a pass!
I never saw page printing 20$ per hour as mentioned in the instruction, why does it still work tho?
Part of your code is not posted, so we cannot test what is there. In addition, some of the indention of your posted code is incorrect. For example, you have …
yes I can see my mistake now. thanks for point to it. Indentation was by mistake too.
I have one more question. Also @appylpye sorry for shooting all my questions at you ;))) it is because I find your explanations the most conducive to my understanding.
This code passed! Also it is ridiculous that it is giving me a pass considering in the method I don’t have args --angle1-2-3 but below i assign them with self. Why is it even giving me a pass?
However, when i entered the following it didn’t even though it is basically the same thing. do you know why?
added to the code(under check_angles)
self.angle1 = angle1
self.angle = angle2
self.angle = angle3
I know that instruction reads add up the args but even if I have extra code as above it should work. No?
… because the only information the method needs to be given to do its work is a reference to the instance of Triangle on which it is to perform that work. Once given that reference, the method can find the values of angle1, angle2, and angle3 for that instance, and then perform the calculation. Those values were assigned when the instance was first created, and __init__ was called. The information is stored in memory as part of the instance, so there is no reason to assign it again or to pass it through parameters to the check_angles method.
So, after the class and its methods have been defined, you can do the following …
# create an instance of Triangle named my_triangle
my_triangle = Triangle(90,30,60)
# print its number_of_sides
print my_triangle.number_of_sides
# print a result of calling its check_angles method
print my_triangle.check_angles()
When this line is executed …
print my_triangle.check_angles()
… a reference to the my_triangle instance is passed as a reference, via the check_angles method’s self parameter. Then, within that check_angles method, any information that is needed about that instance is available through the name, self.
@appylpye i am at “Instantiate an Object” following instruction step by step and it gives the following error still. in the instance I have to give 3 args as instruction says so however adding self to it as arg in the init makes it four. and that is when error occurs. but i can’t eliminate it as it is in the instruction
Traceback (most recent call last):
File "python", line 15, in <module>
TypeError: __init__() takes exactly 1 argument (4 given)
To initialize a Triangle object, we need to assign three sides, so we need parameters for self, angle1, angle2, and angle3. But you only have a parameter for self in the method header, here …
def __init__(self): # method
Assuming that the __init__ header has been corrected, the first of the following three statements is correct, but in the second and third, you are assigning values to self.angle, instead of to the appropriate instance variables …
@appylpye i am sorry i still didn’t get it right after I added sides as args then adding them up by creating instances nothing seems to be working. Can you pleas explain on the correct code. I am a visual learner and learn better looking at data in comparison. Thanks again!
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):
return self.angle1 + self.angle2 + self.angle3 == 180
# Create a Triangle instance, and assign it to my_triangle.
my_triangle = Triangle(90, 30, 60)
# Output the number of sides.
print my_triangle.number_of_sides
# Output the result of a call to check_angles().
# We do not pass it an explicit argument, because my_triangle,
# the object from which we call the method,
# becomes automatically linked to the first
# (and in this case, only), parameter,
# which we have named self, as is customary.
print my_triangle.check_angles()
Then I added your sent code with my_triangle part–to try to see the difference but it still gave error. the part that is about Creating instance and then printing sides and angles separately I understand.
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):
return self.angle1 + self.angle2 + self.angle3 == 180 # also isn't it syntax error if we return and equalize??
my_triangle = Triangle(90, 30, 60)
print my_triangle.number_of_sides
print my_triangle.check_angle()
I spent so much on this but still can’t figure it out yet. The comments you sent i entered initially too, I think I am entering something wrong before creating instance but can’t figure out. I would appreciate if you could send me whole correct code so I can study it on my own. if anything i will ask afterwards
I kinda wanted to fix that issue too, @mtf I added the argument or left it alone with only self but still didn’t work. I wonder if this code can be kept too while fixing argument issue?
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):
return self.angle1 + self.angle2 + self.angle3 == 180 # also isn't it syntax error if we return and equalize??
my_triangle = Triangle(90, 30, 60)
print my_triangle.number_of_sides
print my_triangle.check_angle()