0
class point:
    def __init__(self,z,d):
        self.x = z
        self.y = d
    def display(self,z,d):
        self.x = self.z
        self.y = self.d
    def setX(self, z):
        self.x = z
    def setY(self, d):
        self.y = d
    def getX(self):
       return self.x
    def getY(self):
       return self.y
    def show(self):
       print(self.x)
       print(self.y)

p1 = point() //error
print("Point P1:")
p1.show()
print("Updated value:")
p1.display(5, 6)
p1.setX(9)
p1.setY(4)
p1.show()
print("Point P2:")
p2=point()
p2.setX(9)
p2.setY(4)
p2.show()
print("Updated value:")
p2.display(6, 3)
p2.show()

My program keep showing me error that z and d are missing in the object section,,i donno how to correct it i keep trying but more n more errors keeps showing up.

Traceback (most recent call last):
  File "P:\xxxyyy.py", line 29, in <module>
    p1 = point() //error
TypeError: __init__() missing 2 required positional arguments: 'z' and 'd'
2
  • what is the error? Commented Sep 25, 2018 at 18:45
  • 2
    When asking about code that produces an exception, please include the complete Traceback in the question: copy and paste it then format it as code. Commented Sep 25, 2018 at 18:48

2 Answers 2

3

Don't forget to pass in z and d in the constructor, eg:

p1 = point(1,2)

Also, in the display function, you try to set self.x to self.z and self.y to self.d. self.z and self.d don't exist (self means it should be a class attribute, which it isn't), you should instead use the function's input parameters:

self.x = z
self.y = d
Sign up to request clarification or add additional context in comments.

3 Comments

... or give those parameters default values in the method definition.
Yep! I just assumed he meant to use the function parameters since they are there and match up to self.z and self.d. Whichever way makes more sense is the better way
i did try putting 1,2 in it,, it wasn't working with that too..also the self thing i wrote it like the statement u told me bout. but since it was showing error so i changed it(silly me duh)
0
class point: 
    def __init__(self,z,d): 
        self.x = z 
        self.y = d 
    def display(self,z,d): 
        self.x = z #not self.z
        self.y = d #not self.d
    def setX(self, z): 
        self.x = z 
    def setY(self, d): 
        self.y = d 
    def getX(self): 
       return self.x 
    def getY(self): 
       return self.y 
    def show(self): 
       print(self.x) 
       print(self.y) 

First fix this, you are updating with display using two new variables that its taking in, so we just cast those variables not self.z / self.d

p1 = point(1,2)
print("Point P1:")
p1.show()

Create your instance with values that it needs __ini__(self, z, d) needs a z and d value

print("Updated value:")
p1.display(5, 6)
p1.setX(9)
p1.setY(4)
p1.show()

If p1.display is updating the values to 5,6 then why update them again with setX/setY pretty much you are making z=5, d=6 then z=9 d=4

And then you just repeat these small errors for p2

2 Comments

thanks for explaining.. about the set n get thing i had the assignment to do it in both ways. So thatsy i used display n also set n get fuctions
np would appreciate if this solved your problem if you checked solved :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.