TQC+ 程式語言 Python 3 _108 座標距離計算

說明:
請撰寫一程式,讓使用者輸入四個數字x1、y1、x2、y2,分別代表兩個點的座標(x1, y1)、(x2, y2)。計算並輸出這兩點的座標與其歐式距離。
提示1:歐式距離 = \({ \sqrt{((x1-x2)^2+(y1-y2)^2)} }\)
提示2:兩座標的歐式距離,輸出到小數點後第4位

範例輸入:

2
1
5.5
8
範例輸出:
( 2 , 1 )
( 5.5 , 8 )
Distance = 7.8262
程式碼:
x1 = eval(input())
y1 = eval(input())
x2 = eval(input())
y2 = eval(input())

print("( {} , {} )".format(x1,y1))
print("( {} , {} )".format(x2,y2))
print("Distance = {:.4f}".format(((x1-x2)**2+(y1-y2)**2)**0.5))

沒有留言:

張貼留言