<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div>Hey Guys,<br><br></div>i'm running Python 3.3.2 on Windows 7 64 Bit<br><br></div>I am writing a little script for practice and got a little problem.<br>
</div>I wrote a class which got two points in the constructor (p1 and p2). With the function distanceOf from my class i measure the distance between these two points. Everything works fine. But when i want to use input to get the points i does not work...<br>
<br></div>So how can i get an int tuple with input?<br><br></div>Some Code:<br><br>class points:<br> def __init__(self, p1, p2):<br> self.p1 = p1<br> self.p2 = p2<br> def distanceOf(self):<br> diff = (self.p2[0] - self.p1[0], self.p2[1] - self.p1[1])<br>
a = diff[0]<br> b = diff[1]<br> result = math.sqrt(a**2 + b**2)<br> return "The distance between the two points:", round(result)<br><br></div>When i type test = points((25.0, 30.0), (40.0, 55.0)) and test.distanceOf() everything is ok. Now i wont to get input. (In the input prompt i write: (25.0, 30.0)<br>
</div>p1 = input('Please type in some coordinates') <br></div>p2 = input('Please type in some coordinates')<br></div>test = points(p1, p2)<br></div>points.distanceOf()<br><br>Traceback (most recent call last):<br>
File "lines.py", line 16, in <module><br> line.distanceOf()<br> File "lines.py", line 6, in distanceOf<br> diff = (self.p2[0] - self.p1[0], self.p2[1] - self.p1[1])<br>TypeError: unsupported operand type(s) for -: 'str' and 'str'<br>
<br></div>i get this error<br><br></div>can anyone help me out? How can i get an tuple with int values from user input?<br><br></div>Greetings<br></div>