每次我运行我的代码时,它都会告诉我总数没有定义。我在 support.py 中定义了它,然后将其导入到 stop.py 中。我一直在寻找类似的案例,但我不明白为什么它告诉我这个。请帮忙!
这是停止.py
from support import *
def main():
def get_info():
amplitude = float(input("Amplitude of the sine wave (in feet): "))
period = float(input("Period of the sine wave (in feet): "))
sign = float(input("Distance to the stop sign (in feet): "))
nobrake = float(input("Distance needed to stop without using hand brakes (in feet): "))
step = 9
return amplitude, period, sign, nobrake
get_info()
get_distance(0, 0, 155.3, 134.71)
print("Distance to the stop sign (in feet): 155.3")
print("Distance needed to stop without using hand brakes (in feet): 350.5")
print("Length of the sine wave: ", total)
main()
这是 support.py
import math
def get_sine_length(amplitude, period, x_distance, step):
x = 0.0
total = 0.0
last_x = 0
last_y = 0
while x <= x_distance + (step / 2):
y = math.sin(2 * math.pi / period * x) * amplitude
dist = get_distance(last_x, last_y, x, y)
#print("distance from (", last_x, ",", last_y, ") to (", x, ",", y, ") is", dist)
total = total + dist
last_x = x
last_y = y
x = x + step
return total
def get_distance(a, b, c, d):
dx = c - a
dy = d - b
dsquared = dx**2 + dy**2
result = math.sqrt(dsquared)