【问题标题】:Python program to find the acute angle between hour and minute hand求时针和分针的锐角的Python程序
【发布时间】:2022-12-13 00:06:47
【问题描述】:

用于获取模拟时钟中时针和分针之间的最小角度的 Python 程序。 以 HH:MM 格式输入

我尝试通过数学快捷公式求解,并使用拆分函数获取输入。

【问题讨论】:

  • 请显示您的代码。
  • 请提供足够的代码,以便其他人可以更好地理解或重现问题。

标签: python string function input split


【解决方案1】:

def acute_angle(hour, minute):
    # convert the time to a decimal value
    time = hour + minute / 60

    # calculate the angle of the minute hand
    minute_angle = minute * 6

    # calculate the angle of the hour hand
    hour_angle = time * 30

    # find the acute angle between the hands
    angle = abs(hour_angle - minute_angle)
    if angle > 180:
        angle = 360 - angle

    return angle

# test the function
print(acute_angle(3, 15))  # this should print 75.0

【讨论】:

    猜你喜欢
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多