Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 我的python3代码中不断出现无效语法_Python 3.x - Fatal编程技术网

Python 3.x 我的python3代码中不断出现无效语法

Python 3.x 我的python3代码中不断出现无效语法,python-3.x,Python 3.x,我正在将给定的秒时间转换为小时、分钟和秒。例如,3662可以打印1小时1分钟2秒 def convert_seconds(time): second = time%60.0 minute = int((time%3600)/60.0) hour = int(time/3600) return '%s hour%s, %s minute%s, %s second%s', % (hour, 's' if hour!=1 else '',

我正在将给定的秒时间转换为小时、分钟和秒。例如,
3662
可以打印
1小时1分钟2秒

def convert_seconds(time):
   second = time%60.0
   minute = int((time%3600)/60.0)
   hour = int(time/3600)
   return '%s hour%s, %s minute%s, %s second%s', % (hour, 's' if hour!=1 else '',
                                                    minute, 's' if minute!=1 else '',
                                                    second, 's' if second!=1 else '')
在我的上一个格式代码
%
中有
无效语法。为什么我总是犯这个错误?提前谢谢

格式字符串后有一个额外的逗号(
)字符。应该是:

return '%s hour%s, %s minute%s, %s second%s' % (hour, 's' if hour!=1 else '',
                                                minute, 's' if minute!=1 else '',
                                                second, 's' if second!=1 else '')