2016-10-05 22 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

哇我是哑巴。谢谢 –

相关问题