• Yes, using getter and setter is a better way. But that is not what this kata asks for.

  • Thank you.

  • The exact same question was answered in the third post below yours.

  • Magnitude is not a method, it should be implemented as a property.

  • The tests for my solution pass except for exit... curious if this is an issue with the test (code in python):

    Traceback (most recent call last):
    File "main.py", line 19, in
    test.assert_approx_equals(Vector(examples[0]).magnitude, 3.741, 0.001)
    File "/runner/frameworks/python/cw-2.py", line 84, in assert_approx_equals
    div = max(abs(actual), abs(expected), 1)
    TypeError: bad operand type for abs(): 'method'

  • Python objects are free to intercept attribute get/set operations.
    And, if all you're doing is getting and setting with no restriction, adding getters and setters for it would be writing a whole lot of code to do exactly nothing different from default behaviour.

  • I'm fairly new to Python OO programming, but is it advisable to access class variables directly? My understanding was to use "getter" functions, but that does not work here for v.x, v.y, v.z, and v.magnitude (v is the Vector) as they're specified and tested without function brackets (e.g,, v.x() )

  • Learned about Python Operator Overloading because of the kata.Thank you @Detry322!!!

  • magnitude should be a property and not a method

  • I have passed all tests except for the magnitude test and am getting the error shown below. My magnitude function works in my personal test, but the error seems to have an issue with the test input. Can anyone provide some insight?

    Traceback (most recent call last):
    File "/runner/frameworks/python/cw-2.py", line 111, in wrapper
    func()
    File "main.py", line 104, in _
    test.assert_approx_equals(Vector(examples[0][:]).magnitude, 3.741, 0.001)
    File "/runner/frameworks/python/cw-2.py", line 84, in assert_approx_equals
    div = max(abs(actual), abs(expected), 1)
    TypeError: bad operand type for abs(): 'method'

  • Without knowing what you are doing it's difficult to say what you are doing wrong :)

  • I pass almost all the random tests but I get 14 errors. I think it all stems from the first error saying that both initializatoins should result in the same vector, what am I doing wrong? In my side IDE when I define a vector with a list, tuple, or just 3 inputs they all show the same in the IDE

  • Description says
    Vector([a,b,c]) # creates a new Vector from the supplied 3D array. Vector(a,b,c) # same as above
    However, test case also gives a Vector((a,b,c)). Maybe point this out in the description?

  • magnitude is a property, not a method. Nothing to fix.

  • Loading more items...