Python 我的秒计算器运行异常

Python 我的秒计算器运行异常,python,Python,我正在用python创建一个程序,该程序以小时、分钟和秒为单位,并将它们相加为秒。当我运行这个程序时,我得到了意外的数字,数百个字符长。我知道它非常笨重,我仍在练习python并提高它的效率,但下面是我的代码 def to_secs(hours, minutes, seconds): fin_time = (hours * 3600) + (minutes * 60) + seconds return fin_time total_hours = input("Ho

我正在用python创建一个程序,该程序以小时、分钟和秒为单位,并将它们相加为秒。当我运行这个程序时,我得到了意外的数字,数百个字符长。我知道它非常笨重,我仍在练习python并提高它的效率,但下面是我的代码

def to_secs(hours, minutes, seconds):
     fin_time = (hours * 3600) + (minutes * 60) + seconds
     return fin_time
total_hours = input("How many hours?")
total_minutes = input("How many minutes?")
total_seconds = input("How many seconds?")
total_time = to_secs(total_hours, total_minutes, total_seconds)
print(total_time)
方法
input()
将数据作为字符串读取

在您的版本中,
string*n(number)
的结果是string的n次

例如,Python中的“abc”*3==“abcabc”

您需要转换为整数

total_hours=int(输入(“多少小时?”)
total_minutes=int(输入(“多少分钟?”)
total_seconds=int(输入(“多少秒?”)