定义闪光距离的函数,该函数采用参数时间间隔(秒)并使用公式计算:
the distance(in kilometers) = time interval(in seconds) * 330 / 1000.
以千米为单位的闪电距离并将其返回。距离应四舍五入到整数。返回值的闪光距离功能必须已经四舍五入。
我有这样的程序,但有些事情是非常错误的,我需要帮助。我该怎么办?
def flash_distance (number_ms):
flash_distance = (number_ms * 330/1000)
round return (flash_distance * 330/1000)
distance_ms = 330
distance = int (input ("How many seconds it took seeing the lightning flash hearing?"))
print ("lightning distance in kilometers:" + str (flash_distance (distance_ms)))
答案 0 :(得分:1)
我认为以下代码可以解决您的问题。在您的代码中,distance_ms
已分配给330,因此用户分配的变量distance
将无效,这通常不会发生。
def flash_distance (number_ms):
flash_distance = (number_ms * 330/1000)
return round (flash_distance)
distance_ms = int (input ("How many seconds it took seeing the lightning flash hearing?"))
print ("lightning distance in kilometers:" + str (flash_distance (distance_ms)))