Jan-17-2021, 03:35 PM
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:
Any ideas where I'm going wrong?
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?