-2

I need these two getters to return the string converted version of the x input or y input. Please take a look at my code, and let me know where I faulter. Thanks!

class V:
    def __init__(self, conv, convy):
        conv = conv
        convy = convy

        self.conv = str(conv)
        self.convy = str(convy)

    def getX(self):
        return self.__conv

    def getY(self):
        return self.__convy
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
german
  • 55
  • 1
  • 1
  • 7
  • 6
    What are those double-underscore prefixes for? `self.conv` is not the same as `self.__conv`. – Daniel Roseman Jul 04 '17 at 14:42
  • 1
    Why do you use `conv = conv` and `convy = convy`? – CLeo-Dev Jul 04 '17 at 14:44
  • Please read ["What is the meaning of a single- and a double-underscore before an object name?"](https://stackoverflow.com/q/1301346/416224) if you wonder why you can't access `v.__self` (at least with that name) outside of the class body. – Kijewski Jul 04 '17 at 14:45

1 Answers1

1

Your getter is defined as:

def getX(self):
    return self.__conv

But self.__conv does not exist. Instead, you defined self.conv.

Therefore, your getter should be:

def getX(self):
    return self.conv

In addtion, in your __init__ method, you assign conv and convy to themselves, which is absolutely useless:

def __init__(self, conv, convy):
    conv = conv
    convy = convy

You should get rid of these two lines that serve no purpose.

Right leg
  • 16,080
  • 7
  • 48
  • 81