-2

请帮我弄清楚这段代码有什么问题;第一个函数工作正常,但第二个函数返回错误的数字。第二个变量 sup post 返回的是自午夜以来经过的剩余分钟数。

 def get_hours(s):
    time=s/3600
    return time

#The get_hour function returns how many hours have passed since midnight. The
# parameter is the time in seconds that has passed since midnight.
def get_minutes_remainder(s):
    hours=get_hours(s)
    minutes=s/60
    a=round(hours)
    b=a-hours
    b=abs(b)
    minutes=minutes*b
    return minutes
4

1 回答 1

1

您需要使用 floor not round (更不用说其他一些逻辑错误):

from math import floor
def get_minutes_remainder(s):
    hours = get_hours(s)
    whole_hours = floor(hours)
    fractional_hours = hours - whole_hours
    return fractional_hours * 60
于 2013-03-05T01:20:51.863 回答