Skip to content

Python 209 距離判斷

Python TQC

題目說明:

請使用選擇敘述撰寫一程式,讓使用者輸入一個點的平面座標x和y值,判斷此點是否與點(5, 6)的距離小於或等於15,如距離小於或等於15顯示【Inside】,反之顯示【Outside】。

Info

計算平面上兩點距離的公式:
\(\sqrt{(x1−x2)^2+(y1−y2)^2}\)

範例輸入1
7
20

範例輸出1

Inside

範例輸入2

30
35

範例輸出2

Outside

Solution

1
2
3
4
5
6
7
x = eval(input())
y = eval(input())
d = (((5 - x)**2)+((6 - y)**2))**0.5
if(d <= 15):
    print("Inside")
else:
    print("Outside")

Last update : 13 novembre 2024
Created : 13 novembre 2024

Comments

Comments