Passing variables between methods in Python?

These need to be instance variables:

class simpleclass(object):
    def __init__(self):
        self.x = None
        self.y = None

    def getinput(self):
        self.x = input("input value for x: ")
        self.y = input("input value for y: ")
   
    def calculate(self, z):
        print(self.x + self.y + z)

Leave a Comment