Jan-23-2021, 08:45 PM
FYI x1 is not the same as x[1] or x[increment]. x1 is a variable name and x[1] is a reference to a list element. I've added two lists to the
Personally, I would reconsider the use your class variable --hiddenVar.
get_nums ()
method so that you can reference your variables as list elements.Personally, I would reconsider the use your class variable --hiddenVar.
class Input_Points: __hiddenVar = 0 #hidden variable, to be used only within this class for increments # constructor, arguement receives 4 instance attributes #def __init__(self,x1, y1, x2, y2, __hiddenVar): def __init__(self, x1, y1, x2, y2): self.x1 = x1 self.y1 = y1 self.x2 = x2 self.y2 = y2 # self.__hiddenVar = __hiddenVar """Get integers from user""" def set_nums(self): self.x1 = int(input('enter x1: ')) self.y1 = int(input('enter y1: ')) self.x2 = int(input('enter x2: ')) self.y2 = int(input('enter y2: ')) """ #code below works # format the results, using string formatting def get_nums(self): return print("point 1 = ({},{})".format(self.x1, self.y1)) """ # format the results, using string formatting def get_nums(self, increment): x = [self.x1, self.x2] y = [self.y1, self.y2] while (increment < 2): #print("point", increment, "= ({},{})".format(self.x1, self.y1)) print("point", increment, "= ({},{})".format(x[increment], y[increment])) increment += 1 #return print("point = ", increment, "{},{}".format(self.x1, self.y1)) # Class: Input_Points w1 = Input_Points("","","","") # no default parameters w1.set_nums() #w1.get_nums() w1.get_nums(w1._Input_Points__hiddenVar)