lundi 8 mai 2017

Why is my program not comparing return values in an if, elif, else statement?

The problem I am having is that even if Point M is shorter to P than Point M or vice-versa, the program only prints that they are the same distance. Could this be a problem with my return values? or with the if, elif, else statements?

import math
print("This Program takes the coordinates of two points (Point M and N) and uses the distance formula to find which "
      "point is closer to Point P (-1, 2).")

x_P = -1
y_P = 2

def main():
    x_1 = int(input("Enter an x coordinate for the first point: "))
    y_1 = int(input("Enter an x coordinate for the first point: "))
    x_2 = int(input("Enter an x coordinate for the second point: "))
    y_2 = int(input("Enter an x coordinate for the second point: "))
    distance(x_1, y_1, x_2, y_2)
    distance1 = 0
    distance2 = 0
    if distance1 < distance2:
        print("Point M is closer to Point P.")
    elif distance1 > distance2:
        print("Point N is closer to Point P.")
    else:
        print("Points M and N are the same distance from Point P.")


def distance(x_1, y_1, x_2, y_2):
    distance1 = math.sqrt((x_P - x_1) ** 2 + (y_P - y_1) ** 2)
    distance2 = math.sqrt((x_P - x_2) ** 2 + (y_P - y_2) ** 2)
    return distance1, distance2


main()

Aucun commentaire:

Enregistrer un commentaire