Python Forum
Adding graph points and formating
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding graph points and formating
#4
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 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)
Reply


Messages In This Thread
RE: Adding graph points and formating - by BashBedlam - Jan-23-2021, 08:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Formating generated .data file to XML malcoverc 3 1,416 Apr-14-2022, 09:41 PM
Last Post: malcoverc
  creating two points (x,y) and adding them together.. azhag 2 3,279 Nov-20-2021, 07:22 AM
Last Post: ghoul
  propper formating paracelsusx 2 1,955 Jul-16-2021, 09:17 AM
Last Post: perfringo
  pylab, labeling points on a graph. Dasiey12 0 1,720 Apr-04-2021, 01:08 AM
Last Post: Dasiey12
  Excel: Apply formating of a sheet(file1) to another sheet(file2) lowermoon 1 2,091 May-26-2020, 07:57 AM
Last Post: buran
  Adding markers to Folium map only adding last element. tantony 0 2,175 Oct-16-2019, 03:28 PM
Last Post: tantony
  Issue with ginput and adding points to an exisiting plot gaminer 0 1,656 Oct-12-2019, 07:08 PM
Last Post: gaminer
  tuple and formating problem darktitan 7 3,492 Feb-17-2019, 07:37 PM
Last Post: marienbad
  finding angle between three points on a 2d graph qrani 4 14,211 Nov-20-2018, 06:10 AM
Last Post: Gribouillis
  pymysql: formating ouput of query wardancer84 18 8,539 Oct-04-2018, 01:54 PM
Last Post: wardancer84

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020