Python Forum
Adding graph points and formating
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding graph points and formating
#1
Hi,

I'm creating a code to input 2 points, (x,y) from the user. I've done that, and now I'd like to add these. However, I want to display the points which were input first. I know there's a problem in these lines:

    def get_nums(self):
        return "{[0],[1]}".format(self.x1, self.y1)
What I'd like to do is something like this, but it won't work:

    def get_nums(self):
        return "point 1 = ", "{[0],[1]}".format(self.x1, self.y1)
Here's my full code:
class Input_Points:

    # constructor, arguement receives 4 instance attributes
    def __init__(self,x1, y1, x2, y2):
        self.x1 = x1
        self.y1 = y1
        self.x2 = x2
        self.y2 = y2

    """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: '))

    def get_nums(self):
        return "{[0],[1]}".format(self.x1, self.y1)

# Class: Input_Points
w1 = Input_Points("","","","") # no default parameters
w1.set_nums()
w1.get_nums()
When I run the code, it takes the points, but then returns this error:

Quote: return "{[0],[1]}".format(self.x1, self.y1)
TypeError: 'int' object is not subscriptable

Any ideas where I'm going wrong?
Reply


Messages In This Thread
Adding graph points and formating - by project_science - Jan-17-2021, 03:35 PM

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