0

関数を作成しました

 def distance(x0, y0, x1, y1):
       import math
       return math.sqrt((x1 - x0)**2 + (y1 - y0)**2)

それをdistance.pyとして保存し、コードを実行しようとしました

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())

x0 =10, y0=20, x1=50 y1=50答えを使用する必要がありますが50.0、「0x058625D0での関数距離」が表示されます

助けてください

4

1 に答える 1

2

Switch your code to:

from distance import distance
x0=float(input("Please input x0: "))
y0=float(input("Please input y0: "))
x1=float(input("Please input x1: "))
y1=float(input("Please input y1: "))
print ("")
print (distance(x0, y0, x1, y1))

You need to first convert the input values into floats so they work in your function, and then you need to actually pass them to your function.

于 2013-03-10T09:11:32.090 に答える