2016-10-05 37 views
-2

我試圖做一個程序來計算兩個用戶輸入點之間的距離。我怎樣才能解決這個問題,使其工作?到目前爲止,我有這個試圖製作一個點對點計算器。不支持的操作數類型?

import math 

p1 = [int(input("PLease enter point 1x\n")), (input("Please enter point 1y\n"))] 
p2 = [int(input("PLease enter point 2x\n")), (input("Please enter point 2y\n"))] 
distance = math.sqrt(((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2)) 

print(distance) 

,它在我吐出來的錯誤是:類型錯誤:不支持的操作類型爲 - :「海峽」和「海峽」

我在準備這個正確的方式呢?

+6

你沒有投你的第二組輸入到'int' – idjaw

+0

哇我是啞巴。謝謝 –

回答

1

@idjaw說的很多。你錯過了第二集中的int轉換。
進口數學

p1 = [int(input("PLease enter point 1x\n")), int(input("Please enter point 1y\n"))] 
p2 = [int(input("PLease enter point 2x\n")), int(input("Please enter point 2y\n"))] 
distance = math.sqrt(((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2)) 

print(distance) 
+0

哇我是啞巴。謝謝 –

相關問題