Hi,
Am a total newbie to programming & trying to learn python thro pdf tutorials.
I have this working code which uses four numbers as arguments to calculate the distance between 2 points.
Tried to unsuccessfully convert it to use Class.
Can some one guide me & can I request a simple explaination or some pointers or links to very simple:) explainations for Class,objects, etc.
#Program to calculate distance so that it takes two Points as arguments instead of four numbers.
import math
class Point:
pass
first = Point()
second = Point()
first.x = float(input('Pls enter the x co-ordinate of the first point:')) #eg 3.0
first.y = float(input('Pls enter the y co-ordinate of the first point:')) #eg 4.0
second.x = float(input('Pls enter the x co-ordinate of the second point:')) #eg 6.0
second.y = float(input('Pls enter the y co-ordinate of the second point:')) #eg 8.0
def dist(x1,y1,x2,y2):
dist = math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
return dist
dist = dist(first.x, first.y, second.x, second.y)
print(dist)
Thanks