私が抱えている問題は、ポイントMがポイントMよりも短くても、ポイントMよりも短くても、プログラムは同じ距離であることを印刷するだけです。これは私の戻り値に問題がありますか? if、elif、else文を使用していますか?には何もありません()私のプログラムは、if、elif、else文の戻り値を比較しないのはなぜですか?
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()
ありがとうございました!すべてが正しく機能するようにしました! – AndroidFan253