如何计算Python中输入的小时、分钟和秒的总秒数?
有什么办法吗?我被卡住了 我想出了如何计算Python中输入的小时、分钟和秒的总秒数?,python,python-3.x,Python,Python 3.x,有什么办法吗?我被卡住了 我想出了 >>> def print_seconds(hours, minutes, seconds): ... print(int(hours) * 3600) ... print(int(minutes) * 60) ... print(int(seconds) * 1) ... >>> print_seconds(1,2,3) 3600 120 3 但是我如何总结呢?你在找这样的东西吗 def pr
>>> def print_seconds(hours, minutes, seconds):
... print(int(hours) * 3600)
... print(int(minutes) * 60)
... print(int(seconds) * 1)
...
>>> print_seconds(1,2,3)
3600
120
3
但是我如何总结呢?你在找这样的东西吗
def print_seconds(hours, minutes, seconds):
hours = (int(hours) * 3600)
minutes = (int(minutes) * 60)
seconds = (int(seconds) * 1)
totalTime = hours + minutes + seconds
print(totalTime)
输出
3600
120
3
3723
您不需要创建变量。可以直接声明现有公式。我只是展示它,这样你就可以很容易地看到它。类似于
print(int(小时)*3600+int(分钟)*60+int(秒))
?而且,对于已经是整数的值,也不需要调用int(…)
。是的。谢谢我现在觉得自己很笨,伊扎特,太好了,谢谢!
def print_seconds(hours,minutes,seconds):
return (int(hours)*3600)+(int(minutes)*60)+(int(seconds))
def print_seconds(hours,minutes,seconds):
return (int(hours)*3600)+(int(minutes)*60)+(int(seconds))