Learn Special Methods by Building a Vector Space - Step 68

I can’t pass the Step 68. I think my code is correct. I also tried printing it and it works.

    def __le__(self, other):
        if type(self) != type(other):
            return NotImplemented
        return self.norm() <= other.norm()

print(v1<=v2) 

By the way, I think the instruction…’ return the opposite of self > other’ …is not very happy as we need to use ‘<=’. Opposite of ‘>’ is ‘<’ or not???

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0

Challenge Information:

Learn Special Methods by Building a Vector Space - Step 68

Hi, @maria.kolouchova

Regarding your problem, would this post help?

I have read it, but I still don’t understand it. The post is closed now, so I opened a new one.

If you have a set of numbers: 1,2,3,4,5

Numbers > 3:  4,5
Numbers < 3:  1,2
Numbers <= 3: 1,2,3

In this sense, all the numbers in the set that are not “greater than 3” (4,5) are “less than or equal to 3” (1,2,3). This is what it means by the opposite of greater than. It’s not quite “the opposite” is it…

All numbers in the set that are not > 3 are <= 3.

Thank you for your answer. I think I followed your suggestion, but it still doesn’t work.

    def __le__(self, other):
        if type(self) != type(other):
            return NotImplemented
        return not self.norm() > other.norm()

The logic here ensures that self is not greater than other, meaning it is less than or equal to. However, I still feel there should logically be a <= operator. I’m stuck at this point.

You need to use > as asked:

make it return the opposite of self > other .

You can directly do the comparison of the two because you have already implemented gt

Ok, I got it… The issue was with how I approached the logic. I realized I didn’t need to explicitly call methods on self and other because the logic of a previous method already handles that.