0
我創建的函數從模塊蟒蛇進口功能3
def distance(x0, y0, x1, y1):
import math
return math.sqrt((x1 - x0)**2 + (y1 - y0)**2)
並將其保存爲distance.py 然後我試圖運行使用x0 =10, y0=20, x1=50 y1=50
代碼
from distance import distance
x0=input("Please input x0")
y0=input("Please input y0")
x1=input("Please input x1")
y1=input("Please input y1")
print ("")
print (distance())
答案應該是50.0
,但我得到「功能距離爲0x058625D0」
請幫忙
你確定你沒有'print(distance)'?無論哪種方式,您都沒有將任何參數傳遞給函數 – Blender 2013-03-05 04:36:39
您還沒有將參數傳遞給函數 – avasal 2013-03-05 04:38:07
,您需要將輸入字符串轉換爲數字,例如'x0 = float(input())'(Python 3) 。在函數外面移動'import math'。 – jfs 2013-03-05 05:01:48