0

定义闪光距离函数,它采用参数时间间隔(秒)并用公式计算:

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

1 回答 1

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))) 
于 2017-03-30T07:08:50.393 回答